local: Call library add with tags and duration if asked to

This commit is contained in:
Thomas Adamcik 2014-12-31 18:18:01 +01:00
parent 69d3f90628
commit 12cc2ed35c
2 changed files with 17 additions and 4 deletions

View File

@ -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

View File

@ -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)