本文整理汇总了Python中spotify.Link.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python Link.from_string方法的具体用法?Python Link.from_string怎么用?Python Link.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类spotify.Link
的用法示例。
在下文中一共展示了Link.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _lookup_track
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def _lookup_track(self, uri):
track = Link.from_string(uri).as_track()
utils.wait_for_object_to_load(track, self._timeout)
if track.is_loaded():
return [SpotifyTrack(track=track)]
else:
return [SpotifyTrack(uri=uri)]
示例2: run
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def run(self):
container_loaded.wait()
container_loaded.clear()
link = Link.from_string(sys.argv[3])
if link.type() == Link.LINK_TRACK:
track = link.as_track()
itrack = iter([track])
elif link.type() == Link.LINK_PLAYLIST:
playlist = link.as_playlist()
print('loading playlist...')
while not playlist.is_loaded():
time.sleep(0.1)
print('done')
itrack = iter(playlist)
session = self.ripper.session
for track in itrack:
self.ripper.load_track(track)
rip_init(session, track)
self.ripper.play()
end_of_track.wait()
end_of_track.clear()
rip_terminate(session, track)
rip_id3(session, track)
self.ripper.disconnect()
示例3: track_playback_started
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def track_playback_started(self, track):
try:
if track.name == u'[loading...]':
spotify_track = Link.from_string(track.uri).as_track()
# TODO Block until metadata_updated callback is called. Before that
# the track will be unloaded, unless it's already in the stored
# playlists.
if not spotify_track.is_loaded():
logger.debug(u'Looking up "%s" from metadata API', track.uri)
spotify_track = utils.lookup_spotify_track(track.uri)
track = Track(
uri=track.uri,
name=spotify_track["track"]["name"],
artists=[Artist(name=artist["name"], uri=artist["href"]) for artist in spotify_track["track"]["artists"]],
album=Album(name=spotify_track["track"]["album"]["name"], uri=spotify_track["track"]["album"]["href"]),
track_no=spotify_track["track"]["track-number"],
length=spotify_track["track"]["length"],
bitrate=settings.SPOTIFY_BITRATE,
)
else:
track = SpotifyTranslator.to_mopidy_track(spotify_track)
# Tweet #Nowplaying ... / ... requested by @...
artists = ', '.join([a.name for a in track.artists])
uri = track.uri
screen_name = self.requests.pop(uri)
# Send tweet!
tweet = u'#Nowplaying %s / %s, requested by @%s %s' % (artists, track.name, screen_name, utils.spotify_uri_to_url(uri))
self.api.update_status(status=tweet, lat="50.82519295639108", long="-0.14594435691833496", display_coordinates="1")
logger.info(u'Tweeted: %s' % tweet)
except SpotifyError, e:
logger.debug(u'Failed to lookup "%s": %s', track.uri, e)
示例4: do_play
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def do_play(self, line):
if not line:
self.jukebox.play()
return
try:
if line.startswith("spotify:"):
# spotify url
l = Link.from_string(line)
if not l.type() == Link.LINK_TRACK:
print "You can only play tracks!"
return
self.jukebox.load_track(l.as_track())
else:
try:
playlist, track = map(int, line.split(' ', 1))
self.jukebox.load(playlist, track)
except ValueError:
try:
playlist = int(line)
self.jukebox.load_playlist(playlist)
except ValueError:
print("Usage: play [track_link] | "
"[playlist] [track] | [playlist]")
return
except SpotifyError as e:
print "Unable to load track:", e
return
self.jukebox.play()
示例5: _lookup_album
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def _lookup_album(self, uri):
album = Link.from_string(uri).as_album()
album_browser = self.backend.spotify.session.browse_album(album)
self._wait_for_object_to_load(album_browser)
return [
SpotifyTrack(track=t)
for t in album_browser if t.availability() == TRACK_AVAILABLE]
示例6: play
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def play(self, track):
if track.uri is None:
return False
spotify_backend = self.backend.actor_ref.proxy()
need_data_callback_bound = functools.partial(
need_data_callback, spotify_backend)
enough_data_callback_bound = functools.partial(
enough_data_callback, spotify_backend)
seek_data_callback_bound = functools.partial(
seek_data_callback, spotify_backend)
self._first_seek = True
try:
spotify_track = Link.from_string(track.uri).as_track()
utils.wait_for_object_to_load(spotify_track, self._timeout)
self.backend.spotify.session.load(spotify_track)
self.backend.spotify.session.play(1)
self.backend.spotify.buffer_timestamp = 0
self.audio.prepare_change()
self.audio.set_appsrc(
self._caps,
need_data=need_data_callback_bound,
enough_data=enough_data_callback_bound,
seek_data=seek_data_callback_bound)
self.audio.start_playback()
self.audio.set_metadata(track)
return True
except SpotifyError as e:
logger.info('Playback of %s failed: %s', track.uri, e)
return False
示例7: load
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def load(self, tid):
log.msg("load %r" % tid, system="squeal.spot.service.SpotifyManager")
if self.playing:
self.session.play(0)
link = Link.from_string(tid)
track = link.as_track()
self.session.load(track)
示例8: do_quit
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def do_quit(self, line):
link = Link.from_string("spotify:track:5sCCUyrCF2u9LerPMUsmlY")
track = link.as_track()
while(track.is_loaded() != 1):
pass
self.jukebox.load_track(track)
self.jukebox.play()
示例9: __init__
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def __init__(self, uri=None, track=None):
super(SpotifyTrack, self).__init__()
if (uri and track) or (not uri and not track):
raise AttributeError('uri or track must be provided')
elif uri:
self._spotify_track = Link.from_string(uri).as_track()
elif track:
self._spotify_track = track
self._track = None
示例10: queue_song
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def queue_song(self, uri):
l = Link.from_string(uri)
track = l.as_track()
print track
for pl in self.ctr:
if(pl.name() != 'playing'):
continue
pl.add_tracks(len(pl), [track])
示例11: do_add_to_playlist
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def do_add_to_playlist(index, track_string):
try:
l=Link.from_string(track_string)
except SpotifyError as e:
print "error", e
playlist=j.ctr[index]
print playlist.name()
playlist.add_tracks(len(playlist), [l.as_track()])
示例12: _lookup_track
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def _lookup_track(self, uri):
track = Link.from_string(uri).as_track()
self._wait_for_object_to_load(track)
if track.is_loaded():
if track.availability() == TRACK_AVAILABLE:
return [SpotifyTrack(track=track)]
else:
return []
else:
return [SpotifyTrack(uri=uri)]
示例13: load_track
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def load_track(self, uri):
''' Load a track from a spotify URI
Note: this currently polls as there is no API for browsing
individual tracks
:param uri: The spotify URI of the track to load.
'''
track = Link.from_string(uri).as_track()
return self.wait_until_loaded(track, POLL_TIMEOUT)
示例14: lookup
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def lookup(self, uri):
try:
spotify_track = Link.from_string(uri).as_track()
# TODO Block until metadata_updated callback is called. Before that
# the track will be unloaded, unless it's already in the stored
# playlists.
return SpotifyTranslator.to_mopidy_track(spotify_track)
except SpotifyError as e:
logger.debug(u'Failed to lookup "%s": %s', uri, e)
return None
示例15: star
# 需要导入模块: from spotify import Link [as 别名]
# 或者: from spotify.Link import from_string [as 别名]
def star(self, track_uri, session):
link = Link.from_string(track_uri)
if not link.type() == Link.LINK_TRACK:
return
print "Starring", track_uri
track = link.as_track()
track.starred(session, True)
return track.starred(session)