本文整理汇总了Python中mopidy.models.Ref类的典型用法代码示例。如果您正苦于以下问题:Python Ref类的具体用法?Python Ref怎么用?Python Ref使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Ref类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_as_list_with_folders_and_ignored_unloaded_playlist
def test_as_list_with_folders_and_ignored_unloaded_playlist(provider):
result = provider.as_list()
assert len(result) == 2
assert result[0] == Ref.playlist(uri="spotify:user:alice:playlist:foo", name="Foo")
assert result[1] == Ref.playlist(uri="spotify:playlist:bob:baz", name="Bar/Baz (by bob)")
示例2: country_to_ref
def country_to_ref(country_code):
uri = unparse_uri('country', country_code.lower())
try:
country = pycountry.countries.get(alpha2=country_code.upper())
return Ref.directory(uri=uri, name=country.name)
except KeyError:
return Ref.directory(uri=uri, name=country_code.upper())
示例3: ref
def ref(obj, uri=uri):
identifier = obj['identifier']
mediatype = obj['mediatype']
if mediatype == 'collection':
return Ref.directory(name=name(obj), uri=uri(identifier))
else:
return Ref.album(name=name(obj), uri=uri(identifier))
示例4: setUp
def setUp(self):
dummy1_root = Ref.directory(uri='dummy1:directory', name='dummy1')
self.backend1 = mock.Mock()
self.backend1.uri_schemes.get.return_value = ['dummy1']
self.backend1.actor_ref.actor_class.__name__ = 'dummy1'
self.library1 = mock.Mock(spec=backend.LibraryProvider)
self.library1.root_directory.get.return_value = dummy1_root
self.backend1.library = self.library1
dummy2_root = Ref.directory(uri='dummy2:directory', name='dummy2')
self.backend2 = mock.Mock()
self.backend2.uri_schemes.get.return_value = ['dummy2']
self.backend2.actor_ref.actor_class.__name__ = 'dummy2'
self.library2 = mock.Mock(spec=backend.LibraryProvider)
self.library2.root_directory.get.return_value = dummy2_root
self.backend2.library = self.library2
# A backend without the optional library provider
self.backend3 = mock.Mock()
self.backend3.uri_schemes.get.return_value = ['dummy3']
self.backend3.actor_ref.actor_class.__name__ = 'dummy3'
self.backend3.has_library().get.return_value = False
self.backend3.has_library_browse().get.return_value = False
self.core = core.Core(audio=None, backends=[
self.backend1, self.backend2, self.backend3])
示例5: __init__
def __init__(self, *args, **kwargs):
super(GMusicLibraryProvider, self).__init__(*args, **kwargs)
self.tracks = {}
self.albums = {}
self.artists = {}
self.aa_artists = {}
self.aa_tracks = LruCache()
self.aa_albums = LruCache()
self.all_access = False
self._radio_stations_in_browse = (
self.backend.config['gmusic']['radio_stations_in_browse'])
self._radio_stations_count = (
self.backend.config['gmusic']['radio_stations_count'])
self._radio_tracks_count = (
self.backend.config['gmusic']['radio_tracks_count'])
self._root = []
self._root.append(Ref.directory(uri='gmusic:album', name='Albums'))
self._root.append(Ref.directory(uri='gmusic:artist', name='Artists'))
# browsing all tracks results in connection timeouts
# self._root.append(Ref.directory(uri='gmusic:track', name='Tracks'))
if self._radio_stations_in_browse:
self._root.append(Ref.directory(uri='gmusic:radio',
name='Radios'))
# show root only if there is something to browse
if len(self._root) > 0:
GMusicLibraryProvider.root_directory = Ref.directory(
uri='gmusic:directory', name='Google Music')
示例6: setUp
def setUp(self): # noqa: N802
dummy1_root = Ref.directory(uri='dummy1:directory', name='dummy1')
self.backend1 = mock.Mock()
self.backend1.uri_schemes.get.return_value = ['dummy1']
self.backend1.actor_ref.actor_class.__name__ = 'DummyBackend1'
self.library1 = mock.Mock(spec=backend.LibraryProvider)
self.library1.get_images.return_value.get.return_value = {}
self.library1.root_directory.get.return_value = dummy1_root
self.backend1.library = self.library1
self.backend1.has_playlists.return_value.get.return_value = False
dummy2_root = Ref.directory(uri='dummy2:directory', name='dummy2')
self.backend2 = mock.Mock()
self.backend2.uri_schemes.get.return_value = ['dummy2', 'du2']
self.backend2.actor_ref.actor_class.__name__ = 'DummyBackend2'
self.library2 = mock.Mock(spec=backend.LibraryProvider)
self.library2.get_images.return_value.get.return_value = {}
self.library2.root_directory.get.return_value = dummy2_root
self.backend2.library = self.library2
self.backend2.has_playlists.return_value.get.return_value = False
# A backend without the optional library provider
self.backend3 = mock.Mock()
self.backend3.uri_schemes.get.return_value = ['dummy3']
self.backend3.actor_ref.actor_class.__name__ = 'DummyBackend3'
self.backend3.has_library.return_value.get.return_value = False
self.backend3.has_library_browse.return_value.get.return_value = False
self.core = core.Core(mixer=None, backends=[
self.backend1, self.backend2, self.backend3])
示例7: spotify_browse_process_results
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
示例8: test_browse_root
def test_browse_root(backend, servers):
with mock.patch.object(backend, 'client') as m:
m.servers.return_value = Future.fromvalue(servers)
assert backend.library.browse(backend.library.root_directory.uri) == [
Ref.directory(name='Media Server #1', uri='dleyna://media1'),
Ref.directory(name='Media Server #2', uri='dleyna://media2'),
]
示例9: test_browse_root
def test_browse_root(config, library, genres):
responses.add(responses.GET, re.compile(r'.*/genres\b.*'), json=genres)
assert library.browse('podcast+itunes:') == [
Ref.directory(name='Top Podcasts', uri='podcast+itunes:charts:26'),
Ref.directory(name='Bar', uri='podcast+itunes:genre:1001'),
Ref.directory(name='Foo', uri='podcast+itunes:charts:1000')
]
示例10: _browse_directory
def _browse_directory(self, uri, order=('type', 'name')):
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')
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
示例11: __init__
def __init__(self, *args, **kwargs):
super(GMusicLibraryProvider, self).__init__(*args, **kwargs)
# tracks, albums, and artists here refer to what is explicitly
# in our library.
self.tracks = {}
self.albums = {}
self.artists = {}
# aa_* caches are *only* used for temporary objects. Library
# objects will never make it here.
self.aa_artists = LRUCache(1024)
self.aa_tracks = LRUCache(1024)
self.aa_albums = LRUCache(1024)
self._radio_stations_in_browse = (
self.backend.config['gmusic']['radio_stations_in_browse'])
self._radio_stations_count = (
self.backend.config['gmusic']['radio_stations_count'])
self._radio_tracks_count = (
self.backend.config['gmusic']['radio_tracks_count'])
self._top_tracks_count = (
self.backend.config['gmusic']['top_tracks_count'])
# Setup the root of library browsing.
self._root = [
Ref.directory(uri='gmusic:album', name='Albums'),
Ref.directory(uri='gmusic:artist', name='Artists'),
Ref.directory(uri='gmusic:track', name='Tracks')
]
if self._radio_stations_in_browse:
self._root.append(Ref.directory(uri='gmusic:radio',
name='Radios'))
示例12: setUp
def setUp(self): # noqa: N802
dummy1_root = Ref.directory(uri='dummy1:directory', name='dummy1')
self.backend1 = mock.Mock()
self.backend1.uri_schemes.get.return_value = ['dummy1']
self.library1 = mock.Mock(spec=backend.LibraryProvider)
self.library1.get_images().get.return_value = {}
self.library1.get_images.reset_mock()
self.library1.root_directory.get.return_value = dummy1_root
self.backend1.library = self.library1
dummy2_root = Ref.directory(uri='dummy2:directory', name='dummy2')
self.backend2 = mock.Mock()
self.backend2.uri_schemes.get.return_value = ['dummy2', 'du2']
self.library2 = mock.Mock(spec=backend.LibraryProvider)
self.library2.get_images().get.return_value = {}
self.library2.get_images.reset_mock()
self.library2.root_directory.get.return_value = dummy2_root
self.backend2.library = self.library2
# A backend without the optional library provider
self.backend3 = mock.Mock()
self.backend3.uri_schemes.get.return_value = ['dummy3']
self.backend3.has_library().get.return_value = False
self.backend3.has_library_browse().get.return_value = False
self.core = core.Core(mixer=None, backends=[
self.backend1, self.backend2, self.backend3])
示例13: test_as_list
def test_as_list(self):
result = self.provider.as_list()
self.assertEqual(len(result), 2)
self.assertEqual(
result[0], Ref.playlist(uri='gmusic:playlist:boo', name='boo'))
self.assertEqual(
result[1], Ref.playlist(uri='gmusic:playlist:foo', name='foo'))
示例14: test_lsinfo_duplicate
def test_lsinfo_duplicate(self):
self.backend.library.dummy_browse_result = {
"dummy:/": [Ref.directory(uri="dummy:/a1", name="a"), Ref.directory(uri="dummy:/a2", name="a")]
}
self.sendRequest('lsinfo "/dummy"')
self.assertInResponse("directory: dummy/a")
self.assertInResponse("directory: dummy/a [2]")
示例15: test_lsinfo_for_root_includes_dirs_for_each_lib_with_content
def test_lsinfo_for_root_includes_dirs_for_each_lib_with_content(self):
self.backend.library.dummy_browse_result = {
"dummy:/": [Ref.track(uri="dummy:/a", name="a"), Ref.directory(uri="dummy:/foo", name="foo")]
}
self.sendRequest('lsinfo "/"')
self.assertInResponse("directory: dummy")
self.assertInResponse("OK")