Merge pull request #980 from adamcik/feature/add-tags-and-duration-to-local-library-add
Add tags and duration to local library add()
This commit is contained in:
commit
83a5246074
@ -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`)
|
||||
|
||||
@ -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 :meth:`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
|
||||
:attr:`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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user