本文整理汇总了Python中spotify.Link类的典型用法代码示例。如果您正苦于以下问题:Python Link类的具体用法?Python Link怎么用?Python Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: action_search
def action_search(self, line):
if not line:
if self.results is False:
print "No search is in progress"
return False
elif self.results is None:
print "Searching is in progress"
else:
print "Artists:"
for a in self.results.artists():
print " ", Link.from_artist(a), a.name()
print "Albums:"
for a in self.results.albums():
print " ", Link.from_album(a), a.name()
print "Tracks:"
for a in self.results.tracks():
print " ", Link.from_track(a, 0), a.name()
print self.results.total_tracks() - len(self.results.tracks()), "Tracks not shown"
self.results = False
else:
self.results = None
def _(results, userdata):
print "\nSearch results received"
self.results = results
self.search(line, _)
示例2: do_search
def do_search(self, line):
if not line:
if self.results is False:
print "No search is in progress"
elif self.results is None:
print "Searching is in progress"
else:
print "Artists:"
for a in self.results.artists():
print " ", Link.from_artist(a), a.name()
print "Albums:"
for a in self.results.albums():
print " ", Link.from_album(a), a.name()
print "Tracks:"
for a in self.results.tracks():
print " ", Link.from_track(a, 0), a.name()
print self.results.total_tracks() - \
len(self.results.tracks()), "Tracks not shown"
else:
line = line.decode('utf-8')
self.results = None
def search_finished(results, userdata):
print "\nSearch results received"
self.results = results
self.print_search_results()
self.jukebox.search(line, search_finished)
示例3: add_track_results
def add_track_results(self):
print "Tracks:"
tracklist=self.results.tracks()
print " ", str(Link.from_track(tracklist[0], 0))[14:], tracklist[0].name()
f.write(str(Link.from_track(tracklist[0], 0))[14:]+',')
trackList.append(tracklist[0])
print len(trackList)
示例4: print_search_results
def print_search_results(self):
print "Artists:"
for a in self.results.artists():
print " ", Link.from_artist(a), a.name()
print "Albums:"
for a in self.results.albums():
print " ", Link.from_album(a), a.name()
print "Tracks:"
for a in self.results.tracks():
print " ", Link.from_track(a, 0), a.name()
print self.results.total_tracks() - len(self.results.tracks()), \
"Tracks not shown"
示例5: _to_mopidy_track
def _to_mopidy_track(self, spotify_track):
return Track(
uri=str(Link.from_track(spotify_track, 0)),
title=spotify_track.name().decode(ENCODING),
artists=[self._to_mopidy_artist(a)
for a in spotify_track.artists()],
album=self._to_mopidy_album(spotify_track.album()),
track_no=spotify_track.index(),
date=dt.date(spotify_track.album().year(), 1, 1),
length=spotify_track.duration(),
id=self._to_mopidy_id(str(Link.from_track(spotify_track, 0))),
)
示例6: to_mopidy_playlist
def to_mopidy_playlist(cls, spotify_playlist):
if not spotify_playlist.is_loaded():
return Playlist(name=u'[loading...]')
if spotify_playlist.type() != 'playlist':
return
try:
return Playlist(
uri=str(Link.from_playlist(spotify_playlist)),
name=spotify_playlist.name(),
# FIXME if check on link is a hackish workaround for is_local
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist
if str(Link.from_track(t, 0))],
)
except SpotifyError, e:
logger.warning(u'Failed translating Spotify playlist: %s', e)
示例7: run
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()
示例8: _lookup_album
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]
示例9: to_mopidy_artist
def to_mopidy_artist(cls, spotify_artist):
if not spotify_artist.is_loaded():
return Artist(name=u'[loading...]')
return Artist(
uri=str(Link.from_artist(spotify_artist)),
name=spotify_artist.name()
)
示例10: do_play
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()
示例11: _lookup_track
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)]
示例12: load
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)
示例13: add_artist_link
def add_artist_link(self, artist, source):
"""
Add an artist link to the queue.
"""
link = str(Link.from_artist(artist))
if not self._items:
self._items = [ ]
with open('queue.json', 'r') as fp:
self._items = json.load(fp)
found = False
for item in self._items:
if item['link'] == link:
found = True
break
if not found:
while not artist.is_loaded():
time.sleep(0.1)
print 'Adding %s' % artist.name()
self._items.append({
'name': artist.name(),
'link': link,
'source': source,
})
with open('queue.json', 'w') as fp:
json.dump(self._items, fp, indent=2)
return True
示例14: change_track
def change_track(self, track_link):
for index, item in enumerate(self.play_queue):
if str(Link.from_track(item.track)) == track_link:
self.current_track_index = index
return True
return False
示例15: to_mopidy_artist
def to_mopidy_artist(spotify_artist):
if spotify_artist is None:
return
uri = str(Link.from_artist(spotify_artist))
if not spotify_artist.is_loaded():
return Artist(uri=uri, name='[loading...]')
return Artist(uri=uri, name=spotify_artist.name())