当前位置: 首页>>代码示例>>Python>>正文


Python Link.from_string方法代码示例

本文整理汇总了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)]
开发者ID:TheDirectwave,项目名称:mopidy-spotify,代码行数:9,代码来源:library.py

示例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()
开发者ID:jrevillas,项目名称:spotify-mp3-ripper,代码行数:34,代码来源:sputrifis.py

示例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)
开发者ID:swinton,项目名称:mopidyextra,代码行数:36,代码来源:base.py

示例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()
开发者ID:adamcik,项目名称:pyspotify,代码行数:30,代码来源:jukebox.py

示例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]
开发者ID:cave-scorpion,项目名称:mopidy,代码行数:9,代码来源:library.py

示例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
开发者ID:bh,项目名称:mopidy-spotify,代码行数:36,代码来源:playback.py

示例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)
开发者ID:bne,项目名称:squeal,代码行数:9,代码来源:manager.py

示例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()
开发者ID:BigNetwork,项目名称:spotify-daemon,代码行数:10,代码来源:userinterface.py

示例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
开发者ID:TheDirectwave,项目名称:mopidy-spotify,代码行数:11,代码来源:library.py

示例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])
开发者ID:tak30,项目名称:youkbox,代码行数:11,代码来源:clientSpotify.py

示例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()])
开发者ID:msuss,项目名称:eid_project,代码行数:11,代码来源:hello.py

示例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)]
开发者ID:cave-scorpion,项目名称:mopidy,代码行数:12,代码来源:library.py

示例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)
开发者ID:fldc,项目名称:Spotify.bundle,代码行数:12,代码来源:client.py

示例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
开发者ID:Amli,项目名称:mopidy,代码行数:12,代码来源:library.py

示例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)
开发者ID:DriesVandenneucker,项目名称:starrify,代码行数:12,代码来源:starrify.py


注:本文中的spotify.Link.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。