Plugins use import_task.album

This commit is contained in:
Thomas Scholtes 2014-04-25 13:52:03 +02:00
parent ac9ee8ed66
commit e96753f96a
4 changed files with 21 additions and 10 deletions

View file

@ -391,7 +391,8 @@ class ImportTask(object):
if session.config['incremental']: if session.config['incremental']:
self.save_history() self.save_history()
self.cleanup(copy=session.config['copy'], delete=session.config['delete'], self.cleanup(copy=session.config['copy'],
delete=session.config['delete'],
move=session.config['move']) move=session.config['move'])
self._emit_imported(session.lib) self._emit_imported(session.lib)
@ -430,7 +431,8 @@ class ImportTask(object):
def lookup_candidates(self): def lookup_candidates(self):
"""Retrieve and store candidates for this album. """Retrieve and store candidates for this album.
""" """
artist, album, candidates, recommendation = autotag.tag_album(self.items) artist, album, candidates, recommendation = \
autotag.tag_album(self.items)
self.cur_artist = artist self.cur_artist = artist
self.cur_album = album self.cur_album = album
self.candidates = candidates self.candidates = candidates
@ -574,6 +576,13 @@ class ImportTask(object):
self.set_choice(choice) self.set_choice(choice)
session.log_choice(self) session.log_choice(self)
def reload(self):
"""Reload albums and items from the database.
"""
for item in self.imported_items():
item.load()
self.album.load()
# Utilities. # Utilities.
def prune(self, filename): def prune(self, filename):
@ -667,6 +676,9 @@ class SingletonImportTask(ImportTask):
self.set_choice(choice) self.set_choice(choice)
session.log_choice(self) session.log_choice(self)
def reload(self):
self.item.load()
# FIXME The inheritance relationships are inverted. This is why there # FIXME The inheritance relationships are inverted. This is why there
# are so many methods which pass. We should introduce a new # are so many methods which pass. We should introduce a new
@ -1055,8 +1067,9 @@ def plugin_stage(session, func, task):
func(session, task) func(session, task)
# Stage may modify DB, so re-load cached item data. # Stage may modify DB, so re-load cached item data.
for item in task.imported_items(): # FIXME Importer plugins should not modify the database but instead
item.load() # the albums and items attached to tasks.
task.reload()
@pipeline.mutator_stage @pipeline.mutator_stage

View file

@ -278,8 +278,7 @@ class FetchArtPlugin(BeetsPlugin):
# For any other choices (e.g., TRACKS), do nothing. # For any other choices (e.g., TRACKS), do nothing.
return return
album = session.lib.get_album(task.album_id) path = art_for_album(task.album, task.paths, self.maxwidth, local)
path = art_for_album(album, task.paths, self.maxwidth, local)
if path: if path:
self.art_paths[task] = path self.art_paths[task] = path
@ -290,7 +289,7 @@ class FetchArtPlugin(BeetsPlugin):
if task in self.art_paths: if task in self.art_paths:
path = self.art_paths.pop(task) path = self.art_paths.pop(task)
album = session.lib.get_album(task.album_id) album = task.album
src_removed = (config['import']['delete'].get(bool) or src_removed = (config['import']['delete'].get(bool) or
config['import']['move'].get(bool)) config['import']['move'].get(bool))
album.set_art(path, not src_removed) album.set_art(path, not src_removed)

View file

@ -382,7 +382,7 @@ class LastGenrePlugin(plugins.BeetsPlugin):
def imported(self, session, task): def imported(self, session, task):
"""Event hook called when an import task finishes.""" """Event hook called when an import task finishes."""
if task.is_album: if task.is_album:
album = session.lib.get_album(task.album_id) album = task.album
album.genre, src = self._get_genre(album) album.genre, src = self._get_genre(album)
log.debug(u'added last.fm album genre ({0}): {1}'.format( log.debug(u'added last.fm album genre ({0}): {1}'.format(
src, album.genre src, album.genre

View file

@ -601,8 +601,7 @@ class ReplayGainPlugin(BeetsPlugin):
return return
if task.is_album: if task.is_album:
album = session.lib.get_album(task.album_id) self.handle_album(task.album, False)
self.handle_album(album, False)
else: else:
self.handle_track(task.item, False) self.handle_track(task.item, False)