From 12cc2ed35c1935129f828f9a0a5ebc552e8d1b9d Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Wed, 31 Dec 2014 18:18:01 +0100 Subject: [PATCH 1/3] 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) From 663cdf929d89055c8e7d56e38d67c446dc418b3a Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 12 Feb 2015 21:13:50 +0100 Subject: [PATCH 2/3] docs: Add tags/duration local addition to changelog --- docs/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 89090218..640fca97 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -51,6 +51,9 @@ v0.20.0 (UNRELEASED) just like the other ``lookup()`` methods in Mopidy. For now, returning a single track will continue to work. (PR: :issue:`840`) +- Add support for giving local libraries direct access to tags and duration. + (Fixes: :issue:`967`) + **File scanner** - Improve error logging for scan code (Fixes: :issue:`856`, PR: :issue:`874`) From 38158b4430e03c62e512224a3ba8da9bd199b3cb Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Thu, 12 Feb 2015 22:48:05 +0100 Subject: [PATCH 3/3] local: Minor docstring review corrections --- mopidy/local/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mopidy/local/__init__.py b/mopidy/local/__init__.py index 2ec8b79e..31ec6426 100644 --- a/mopidy/local/__init__.py +++ b/mopidy/local/__init__.py @@ -70,8 +70,8 @@ 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. + #: Feature marker to indicate that you want :meth:`add()` calls to be + #: called with optional arguments tags and duration. add_supports_tags_and_duration = False def __init__(self, config): @@ -142,7 +142,7 @@ class Library(object): def add(self, track, tags=None, duration=None): """ Add the given track to library. Optional args will only be added if - `add_supports_tags_and_duration` has been set. + :attr:`add_supports_tags_and_duration` has been set. :param track: Track to add to the library :type track: :class:`~mopidy.models.Track`