本文整理汇总了Python中mopidy_pandora.uri.PandoraUri.factory方法的典型用法代码示例。如果您正苦于以下问题:Python PandoraUri.factory方法的具体用法?Python PandoraUri.factory怎么用?Python PandoraUri.factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mopidy_pandora.uri.PandoraUri
的用法示例。
在下文中一共展示了PandoraUri.factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _browse_genre_stations
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def _browse_genre_stations(self, uri):
return [
models.Ref.directory(name=station.name, uri=PandoraUri.factory(station).uri)
for station in self.backend.api.get_genre_stations()[
PandoraUri.factory(uri).category_name
]
]
示例2: test_factory_returns_correct_station_uri_types
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_factory_returns_correct_station_uri_types():
station_mock = mock.PropertyMock(spec=GenreStation)
station_mock.id = 'G100'
station_mock.token = 'G100'
assert type(PandoraUri.factory(station_mock)) is GenreStationUri
station_mock = mock.PropertyMock(spec=Station)
station_mock.id = 'id_mock'
station_mock.token = 'token_mock'
assert type(PandoraUri.factory(station_mock)) is StationUri
示例3: is_station_changed
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def is_station_changed(self, track):
try:
previous_track_uri = PandoraUri.factory(
self.core.history.get_history().get()[1][1].uri
)
if (
previous_track_uri.station_id
!= PandoraUri.factory(track.uri).station_id
):
return True
except (IndexError, NotImplementedError):
# No tracks in history, or last played track was not a Pandora track. Ignore
pass
return False
示例4: test_get_images_for_unknown_uri_returns_empty_list
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_get_images_for_unknown_uri_returns_empty_list(config, caplog):
backend = conftest.get_backend(config)
track_uri = PandoraUri.factory('pandora:track:mock_id:mock_token')
results = backend.library.get_images([track_uri.uri])
assert len(results[track_uri.uri]) == 0
assert "Failed to lookup image for Pandora URI '{}'.".format(track_uri.uri) in caplog.text
示例5: test_get_images_for_unsupported_uri_type_issues_warning
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_get_images_for_unsupported_uri_type_issues_warning(config, caplog):
backend = conftest.get_backend(config)
search_uri = PandoraUri.factory('pandora:search:R12345')
results = backend.library.get_images([search_uri.uri])
assert len(results[search_uri.uri]) == 0
assert "No images available for Pandora URIs of type 'search'.".format(search_uri.uri) in caplog.text
示例6: test_change_track_skips_if_track_not_available_in_buffer
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_change_track_skips_if_track_not_available_in_buffer(provider, playlist_item_mock, caplog):
track = PandoraUri.factory(playlist_item_mock)
provider.backend.prepare_next_track = mock.PropertyMock()
assert provider.change_track(track) is False
assert "Error changing Pandora track: failed to lookup '{}'.".format(track.uri) in caplog.text
示例7: get_images
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def get_images(self, uris):
result = {}
for uri in uris:
image_uris = set()
try:
track = self.lookup_pandora_track(uri)
if track.is_ad is True:
image_uri = track.image_url
else:
image_uri = track.album_art_url
if image_uri:
image_uris.update([image_uri])
except (TypeError, KeyError):
pandora_uri = PandoraUri.factory(uri)
if isinstance(pandora_uri, TrackUri):
# Could not find the track as expected - exception.
logger.exception(
"Failed to lookup image for Pandora URI '{}'.".format(uri)
)
else:
# Lookup
logger.warning(
"No images available for Pandora URIs of type '{}'.".format(
pandora_uri.uri_type
)
)
pass
result[uri] = [models.Image(uri=u) for u in image_uris]
return result
示例8: test_factory_track
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_factory_track():
track = models.Track(name='name_mock', uri='pandora:track:station_id_mock:track_token_mock')
obj = PandoraUri.factory(track)
assert type(obj) is PlaylistItemUri
assert obj.uri == track.uri
示例9: change_track
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def change_track(self, track):
if track.uri is None:
logger.warning(
"No URI for Pandora track '{}'. Track cannot be played.".format(track)
)
return False
pandora_uri = PandoraUri.factory(track.uri)
if isinstance(pandora_uri, StationUri):
# Change to first track in station playlist.
logger.warning(
"Cannot play Pandora stations directly. Retrieving tracks for station with ID: {}...".format(
pandora_uri.station_id
)
)
self.backend.end_of_tracklist_reached(
station_id=pandora_uri.station_id, auto_play=True
)
return False
try:
self._trigger_track_changing(track)
self.check_skip_limit()
self.change_pandora_track(track)
return super(PandoraPlaybackProvider, self).change_track(track)
except KeyError:
logger.exception(
"Error changing Pandora track: failed to lookup '{}'.".format(track.uri)
)
return False
except (MaxSkipLimitExceeded, Unplayable) as e:
logger.warning(e)
return False
示例10: update_tracklist
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def update_tracklist(self, track):
if self.is_station_changed(track):
# Station has changed, remove tracks from previous station from tracklist.
self._trim_tracklist(keep_only=track)
if self.is_end_of_tracklist_reached(track):
self._trigger_end_of_tracklist_reached(
PandoraUri.factory(track).station_id, auto_play=False
)
示例11: test_lookup_of_missing_track
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_lookup_of_missing_track(config, playlist_item_mock, caplog):
backend = conftest.get_backend(config)
track_uri = PandoraUri.factory(playlist_item_mock)
results = backend.library.lookup(track_uri.uri)
assert len(results) == 0
assert "Failed to lookup Pandora URI '{}'.".format(track_uri.uri) in caplog.text
示例12: test_get_images_for_ad_with_images
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_get_images_for_ad_with_images(config, ad_item_mock):
backend = conftest.get_backend(config)
ad_uri = PandoraUri.factory('pandora:ad:{}:{}'.format(conftest.MOCK_STATION_ID, conftest.MOCK_TRACK_AD_TOKEN))
backend.library.pandora_track_cache[ad_uri.uri] = TrackCacheItem(mock.Mock(spec=models.Ref.track), ad_item_mock)
results = backend.library.get_images([ad_uri.uri])
assert len(results[ad_uri.uri]) == 1
assert results[ad_uri.uri][0].uri == ad_item_mock.image_url
示例13: track_unplayable
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def track_unplayable(self, track):
if self.is_end_of_tracklist_reached(track):
self.core.playback.stop()
self._trigger_end_of_tracklist_reached(
PandoraUri.factory(track).station_id, auto_play=True
)
self.core.tracklist.remove({"uri": [track.uri]})
示例14: test_change_track_fetches_next_track_if_station_uri
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_change_track_fetches_next_track_if_station_uri(provider, get_station_mock_return_value, caplog):
station = PandoraUri.factory(get_station_mock_return_value)
provider.backend._trigger_next_track_available = mock.PropertyMock()
assert provider.change_track(station) is False
assert 'Cannot play Pandora stations directly. Retrieving tracks for station with ID: {}...'.format(
station.station_id) in caplog.text
assert provider.backend._trigger_next_track_available.called
示例15: test_change_track_resets_skips_on_success
# 需要导入模块: from mopidy_pandora.uri import PandoraUri [as 别名]
# 或者: from mopidy_pandora.uri.PandoraUri import factory [as 别名]
def test_change_track_resets_skips_on_success(provider, playlist_item_mock):
with mock.patch.object(PandoraLibraryProvider, 'lookup_pandora_track', return_value=playlist_item_mock):
with mock.patch.object(PlaylistItem, 'get_is_playable', return_value=True):
track = PandoraUri.factory(playlist_item_mock)
provider._consecutive_track_skips = 1
assert provider.change_track(track) is True
assert provider._consecutive_track_skips == 0