From 12cc2ed35c1935129f828f9a0a5ebc552e8d1b9d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 31 Dec 2014 18:18:01 +0100 Subject: [PATCH] local: Call library add with tags and duration if asked to --- mopidy/local/__init__.py | 15 +++++++++++++-- mopidy/local/commands.py | 6 ++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/mopidy/local/__init__.py b/mopidy/local/__init__.py index 62228e91..2ec8b79e 100644 --- a/mopidy/local/__init__.py +++ b/mopidy/local/__init__.py @@ -70,6 +70,10 @@ class Library(object): #: Name of the local library implementation, must be overriden. name = None + #: Feature marker to indicate that you want add calls to be called with + #: optional arguments tags and duration. + add_supports_tags_and_duration = False + def __init__(self, config): self._config = config @@ -135,12 +139,19 @@ class Library(object): """ raise NotImplementedError - def add(self, track): + def add(self, track, tags=None, duration=None): """ - Add the given track to library. + Add the given track to library. Optional args will only be added if + `add_supports_tags_and_duration` has been set. :param track: Track to add to the library :type track: :class:`~mopidy.models.Track` + :param tags: All the tags the scanner found for the media. See + :module:`mopidy.audio.utils` for details about the tags. + :type tags: dictionary of tag keys with a list of values. + :param duration: Duration of media in milliseconds or :class:`None` if + unknown + :type duration: :class:`int` or :class:`None` """ raise NotImplementedError diff --git a/mopidy/local/commands.py b/mopidy/local/commands.py index d49ab8f8..a9920ec8 100644 --- a/mopidy/local/commands.py +++ b/mopidy/local/commands.py @@ -139,8 +139,10 @@ class ScanCommand(commands.Command): track = utils.convert_tags_to_track(tags).copy( uri=uri, length=duration, last_modified=mtime) track = translator.add_musicbrainz_coverart_to_track(track) - # TODO: add tags to call if library supports it. - library.add(track) + if library.add_supports_tags_and_duration: + library.add(track, tags=tags, duration=duration) + else: + library.add(track) logger.debug('Added %s', track.uri) except exceptions.ScannerError as error: logger.warning('Failed %s: %s', uri, error)