Skip to content

Commit

Permalink
acousticbrainz: support standalone recordings again
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Jul 5, 2021
1 parent 44680d2 commit 5b26325
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions plugins/acousticbrainz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@
config,
log,
)
from picard.metadata import register_album_metadata_processor
from picard.metadata import (
register_album_metadata_processor,
register_track_metadata_processor,
)
from picard.ui.options import (
OptionsPage,
register_options_page,
Expand Down Expand Up @@ -286,8 +289,8 @@ class AcousticBrainzRequest:

MAX_BATCH_SIZE = 25

def __init__(self, album, recording_ids):
self.album = album
def __init__(self, webservice, recording_ids):
self.webservice = webservice
self.recording_ids = recording_ids

def request_highlevel(self, callback):
Expand All @@ -310,7 +313,7 @@ def _batch(self, action, recording_ids, callback, result, response=None, reply=N
callback=partial(self._batch, action, recording_ids, callback, result))

def _do_request(self, action, recording_ids, callback):
self.album.tagger.webservice.get(
self.webservice.get(
ACOUSTICBRAINZ_HOST,
ACOUSTICBRAINZ_PORT,
'/api/v1/%s' % action,
Expand Down Expand Up @@ -341,8 +344,19 @@ def _merge_results(self, full, new):
class AcousticBrainzPlugin:

def process_album(self, album, metadata, release):
debug('Processing album %s', album.id)
recording_ids = self.get_recording_ids(release)
request = AcousticBrainzRequest(album, recording_ids)
self.run_requests(album, recording_ids)

def process_track(self, album, metadata, track, release):
# Only run for standaline recordings
if not release and 'id' in track:
recording_ids = [track['id']]
debug('Processing recording %s', recording_ids[0])
self.run_requests(album, recording_ids)

def run_requests(self, album, recording_ids):
request = AcousticBrainzRequest(album.tagger.webservice, recording_ids)
if self.do_highlevel:
album._requests += 1
request.request_highlevel(partial(self.callback, HIGHLEVEL, album))
Expand Down Expand Up @@ -383,6 +397,7 @@ def callback(self, level, album, result=None, error=None):
album._finalize_loading(error)

def update_metadata(self, level, album, result):
debug('Updating %r with %s results for %i tracks', album, level, len(result.keys()))
for track in album.tracks:
processor = TrackDataProcessor(track, level, result)
processor.process()
Expand Down Expand Up @@ -429,4 +444,5 @@ def save(self):

plugin = AcousticBrainzPlugin()
register_album_metadata_processor(plugin.process_album)
register_track_metadata_processor(plugin.process_track)
register_options_page(AcousticBrainzOptionsPage)

0 comments on commit 5b26325

Please sign in to comment.