Skip to content

Commit

Permalink
Add support for directory URIs
Browse files Browse the repository at this point in the history
Allows the user to assign directory URIs to an RFID tag.
All Tracks in the referenced directory and its sub directories
will be added to the tracklist.
  • Loading branch information
ueb committed Feb 28, 2021
1 parent 7590da3 commit 41cdeec
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion mopidy_pummeluff/actions/tracklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ class Tracklist(Action):
parameter.
'''

@classmethod
def _browse_uri(cls, core, uri):
'''
Searches all tracks in uri (if it is a directory) and sub directories.
:param mopidy.core.Core core: The mopidy core instance
:param str uri: the URI
'''
# try to browse it - maybe it is a directory
uris = []
for ref in core.library.browse(uri).get():
if ref.type == ref.TRACK:
uris.append(ref.uri)
elif ref.type == ref.DIRECTORY:
uris.extend(cls._browse_uri(core, ref.uri))


@classmethod
def execute(cls, core, uri): # pylint: disable=arguments-differ
'''
Expand All @@ -34,7 +51,16 @@ def execute(cls, core, uri): # pylint: disable=arguments-differ
if uri in playlists:
uris = [item.uri for item in core.playlists.get_items(uri).get()]
else:
uris = [uri]
# if uri points to a Directory, we have to call browse to get all
# the Tracks. Right now it is not possible to get the type of an
# URI. So we just try to browse uri and if it is not a directory
# this will return an empty list of uris.
uris = cls._browse_uri(core, uri)
if not uris:
# browse failed
uris = [uri]

LOGGER.info(f'uris: {uris}')

core.tracklist.clear()
core.tracklist.add(uris=uris)
Expand Down

0 comments on commit 41cdeec

Please sign in to comment.