本文整理汇总了Python中mopidy.models.Ref.directory方法的典型用法代码示例。如果您正苦于以下问题:Python Ref.directory方法的具体用法?Python Ref.directory怎么用?Python Ref.directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mopidy.models.Ref
的用法示例。
在下文中一共展示了Ref.directory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _browse_artist
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def _browse_artist(self, uri, order=('type', 'name COLLATE NOCASE')):
with self._connect() as c:
albums = schema.browse(c, Ref.ALBUM, order, albumartist=uri)
refs = schema.browse(c, order=order, artist=uri)
album_uris, tracks = {ref.uri for ref in albums}, []
for ref in refs:
if ref.type == Ref.ALBUM and ref.uri not in album_uris:
albums.append(Ref.directory(
uri=uritools.uricompose('local', None, 'directory', dict(
type=Ref.TRACK, album=ref.uri, artist=uri
)),
name=ref.name
))
elif ref.type == Ref.TRACK:
tracks.append(ref)
else:
logger.debug('Skipped SQLite browse result %s', ref.uri)
albums.sort(key=operator.attrgetter('name'))
return albums + tracks
示例2: test_listall_with_uri
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def test_listall_with_uri(self):
tracks = [
Track(uri="dummy:/a", name="a"),
Track(uri="dummy:/foo/b", name="b"),
]
self.backend.library.dummy_library = tracks
self.backend.library.dummy_browse_result = {
"dummy:/": [
Ref.track(uri="dummy:/a", name="a"),
Ref.directory(uri="dummy:/foo", name="foo"),
],
"dummy:/foo": [Ref.track(uri="dummy:/foo/b", name="b")],
}
self.send_request('listall "/dummy/foo"')
self.assertNotInResponse("file: dummy:/a")
self.assertInResponse("directory: /dummy/foo")
self.assertInResponse("file: dummy:/foo/b")
self.assertInResponse("OK")
示例3: test_listallinfo_with_uri
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def test_listallinfo_with_uri(self):
tracks = [
Track(uri="dummy:/a", name="a"),
Track(uri="dummy:/foo/b", name="b"),
]
self.backend.library.dummy_library = tracks
self.backend.library.dummy_browse_result = {
"dummy:/": [
Ref.track(uri="dummy:/a", name="a"),
Ref.directory(uri="dummy:/foo", name="foo"),
],
"dummy:/foo": [Ref.track(uri="dummy:/foo/b", name="b")],
}
self.send_request('listallinfo "/dummy/foo"')
self.assertNotInResponse("file: dummy:/a")
self.assertNotInResponse("Title: a")
self.assertInResponse("directory: /dummy/foo")
self.assertInResponse("file: dummy:/foo/b")
self.assertInResponse("Title: b")
self.assertInResponse("OK")
示例4: setUp
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def setUp(self): # noqa: N802
super().setUp()
self.tracks = [
Track(uri="dummy:/a", name="a"),
Track(uri="dummy:/foo/b", name="b"),
Track(uri="dummy:/foo/ǂ", name="ǂ"),
]
self.refs = {
"/a": Ref.track(uri="dummy:/a", name="a"),
"/foo": Ref.directory(uri="dummy:/foo", name="foo"),
"/foo/b": Ref.track(uri="dummy:/foo/b", name="b"),
"/foo/ǂ": Ref.track(uri="dummy:/foo/ǂ", name="ǂ"),
}
self.backend.library.dummy_library = self.tracks
示例5: _browse_artist
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def _browse_artist(self, uri, order=("type", "name COLLATE NOCASE")):
with self._connect() as c:
albums = schema.browse(c, Ref.ALBUM, order, albumartist=uri)
refs = schema.browse(c, order=order, artist=uri)
album_uris, tracks = {ref.uri for ref in albums}, []
for ref in refs:
if ref.type == Ref.ALBUM and ref.uri not in album_uris:
albums.append(
Ref.directory(
uri=uritools.uricompose(
"local",
None,
"directory",
dict(type=Ref.TRACK, album=ref.uri, artist=uri),
),
name=ref.name,
)
)
elif ref.type == Ref.TRACK:
tracks.append(ref)
else:
logger.debug("Skipped SQLite browse result %s", ref.uri)
albums.sort(key=operator.attrgetter("name"))
return albums + tracks
示例6: spotify_browse_process_results
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def spotify_browse_process_results(results):
logger.debug('Processing spotify browse result')
if 'categories' in results:
result_list = results['categories']
browse_uri = 'spotifyweb:browse:categories:'
arr = [Ref.directory(uri=browse_uri + cat['id'],
name=cat['name'])
for cat in result_list['items']]
elif 'playlists' in results:
result_list = results['playlists']
arr = [Ref.playlist(uri=playlist['uri'],
name=playlist['name'])
for playlist in result_list['items']]
elif 'albums' in results:
result_list = results['albums']
arr = [Ref.album(uri=album['uri'],
name=album['name'])
for album in result_list['items']]
else:
result_list = None
arr = []
cont = result_list is not None and result_list['next'] is not None
logger.debug('Spotify browse result cont: %s' % cont)
return arr, cont
示例7: __init__
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def __init__(self, *args, **kwargs):
super(SpotifyWebLibraryProvider, self).__init__(*args, **kwargs)
self._your_music = \
[Ref.directory(uri='spotifyweb:yourmusic:songs', name='Songs'),
Ref.directory(uri='spotifyweb:yourmusic:albums', name='Albums'),
Ref.directory(uri='spotifyweb:yourmusic:artists', name='Artists')]
self._browse = \
[Ref.directory(uri='spotifyweb:browse:new-releases',
name='New Releases'),
Ref.directory(uri='spotifyweb:browse:categories',
name='Genres & Moods'),
Ref.directory(uri='spotifyweb:browse:featured-playlists',
name='Featured Playlists')]
self._root = \
[Ref.directory(uri='spotifyweb:yourmusic', name='Your Music'),
Ref.directory(uri='spotifyweb:browse', name='Browse'),
Ref.directory(uri='spotifyweb:sauce', name='Your Artists')]
self._sp = None
self._cache = None
self._access_token = None
self._access_token_expires = None
示例8: browse_your_music
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def browse_your_music(self, uri):
if uri == 'spotifyweb:yourmusic':
return self._your_music
if uri == 'spotifyweb:yourmusic:artists':
return self._cache.sortedArtists
# return Ref directory with all artists
elif uri == 'spotifyweb:yourmusic:albums':
return self._cache.sortedAlbums
# return Ref directory for all albums
elif uri.startswith('spotifyweb:yourmusic:artist:'):
# get artist uri
return self._cache.artists2albums.get(uri)
# return Ref directory with all albums for artist
elif uri.startswith('spotifyweb:yourmusic:album:'):
# get album uri
return self._cache.albums2tracks.get(uri)
# return Ref directory with all tracks for album
elif uri == 'spotifyweb:yourmusic:songs':
return self._cache.tracks
else:
return []
示例9: __init__
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def __init__(self, config):
self._config = ext_config = config[Extension.ext_name]
self._data_dir = Extension.get_or_create_data_dir(config)
try:
self._media_dir = config['local']['media_dir']
except KeyError:
raise ExtensionError('Mopidy-Local not enabled')
self._directories = []
for line in ext_config['directories']:
name, uri = line.rsplit(None, 1)
ref = Ref.directory(uri=uri, name=name)
self._directories.append(ref)
self._dbpath = os.path.join(self._data_dir, b'library.db')
self._connection = None
示例10: browse
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def browse(self, uri):
try:
if uri == self.ROOT_DIRECTORY_URI:
return self._directories
elif uri.startswith('local:directory'):
return self._browse_directory(uri)
elif uri.startswith('local:artist'):
return self._browse_artist(uri)
elif uri.startswith('local:album'):
return self._browse_album(uri)
else:
raise ValueError('Invalid browse URI')
except Exception as e:
logger.error('Error browsing %s: %s', uri, e)
return []
示例11: _browse_directory
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def _browse_directory(self, uri, order=('type', 'name COLLATE NOCASE')):
query = dict(uritools.urisplit(uri).getquerylist())
type = query.pop('type', None)
role = query.pop('role', None)
# TODO: handle these in schema (generically)?
if type == 'date':
format = query.get('format', '%Y-%m-%d')
return map(_dateref, schema.dates(self._connect(), format=format))
if type == 'genre':
return map(_genreref, schema.list_distinct(self._connect(), 'genre')) # noqa
# Fix #38: keep sort order of album tracks; this also applies
# to composers and performers
if type == Ref.TRACK and 'album' in query:
order = ('disc_no', 'track_no', 'name')
if type == Ref.ARTIST and self._config['use_artist_sortname']:
order = ('coalesce(sortname, name) COLLATE NOCASE',)
roles = role or ('artist', 'albumartist') # FIXME: re-think 'roles'...
refs = []
for ref in schema.browse(self._connect(), type, order, role=roles, **query): # noqa
if ref.type == Ref.TRACK or (not query and not role):
refs.append(ref)
elif ref.type == Ref.ALBUM:
refs.append(Ref.directory(uri=uritools.uricompose(
'local', None, 'directory', dict(query, type=Ref.TRACK, album=ref.uri) # noqa
), name=ref.name))
elif ref.type == Ref.ARTIST:
refs.append(Ref.directory(uri=uritools.uricompose(
'local', None, 'directory', dict(query, **{role: ref.uri})
), name=ref.name))
else:
logger.warn('Unexpected SQLite browse result: %r', ref)
return refs
示例12: _filters
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def _filters(self, uri):
if uri.startswith('local:directory'):
return [dict(uritools.urisplit(uri).getquerylist())]
elif uri.startswith('local:artist'):
return [{'artist': uri}, {'albumartist': uri}]
elif uri.startswith('local:album'):
return [{'album': uri}]
else:
return []
示例13: _genreref
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def _genreref(genre):
return Ref.directory(
uri=uritools.uricompose('local', None, 'directory', {'genre': genre}),
name=genre
)
示例14: test_listall_without_uri
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def test_listall_without_uri(self):
tracks = [
Track(uri="dummy:/a", name="a"),
Track(uri="dummy:/foo/b", name="b"),
]
self.backend.library.dummy_library = tracks
self.backend.library.dummy_browse_result = {
"dummy:/": [
Ref.track(uri="dummy:/a", name="a"),
Ref.directory(uri="dummy:/foo", name="foo"),
Ref.album(uri="dummy:/album", name="album"),
Ref.artist(uri="dummy:/artist", name="artist"),
Ref.playlist(uri="dummy:/pl", name="pl"),
],
"dummy:/foo": [Ref.track(uri="dummy:/foo/b", name="b")],
}
self.send_request("listall")
self.assertInResponse("file: dummy:/a")
self.assertInResponse("directory: /dummy/foo")
self.assertInResponse("directory: /dummy/album")
self.assertInResponse("directory: /dummy/artist")
self.assertInResponse("directory: /dummy/pl")
self.assertInResponse("file: dummy:/foo/b")
self.assertInResponse("OK")
示例15: test_listall_for_dir_with_and_without_leading_slash_is_the_same
# 需要导入模块: from mopidy.models import Ref [as 别名]
# 或者: from mopidy.models.Ref import directory [as 别名]
def test_listall_for_dir_with_and_without_leading_slash_is_the_same(self):
self.backend.library.dummy_browse_result = {
"dummy:/": [
Ref.track(uri="dummy:/a", name="a"),
Ref.directory(uri="dummy:/foo", name="foo"),
]
}
response1 = self.send_request('listall "dummy"')
response2 = self.send_request('listall "/dummy"')
assert response1 == response2