我不知道如何使用 pyspotify 加载专辑元数据。无论我尝试过什么,专辑浏览器仍在加载。
这是我的课:
当我们在主函数中使用 session.connect() 成功登录时,logged_in 会被回调调用。
class sessionManager(SpotifySessionManager):
appkey_file = os.path.join(os.path.dirname(__file__), 'spotify_appkey.key')
def __init__(self, *a, **kw):
SpotifySessionManager.__init__(self, *a, **kw)
def logged_in(self, session, error):
link=Link.from_string("spotify:album:4DR0GWo7w2GJyQnFVa4jAB")
line=""
if link.type() == link.LINK_ALBUM:
browser = AlbumBrowser(link.as_album())
while not browser.is_loaded():
line+="."
time.sleep(1)
sys.stdout.write("\r%s" % line)
sys.stdout.flush()
for track in browser:
print track.name()
if link.type() == link.LINK_ARTIST:
browser = ArtistBrowser(link.as_artist())
while not browser.is_loaded():
line+="."
time.sleep(1)
sys.stdout.write("\r%s" % line)
sys.stdout.flush()
for album in browser:
print album.name()
这是我的班级如何被调用的:
if __name__ == '__main__':
import optparse
op = optparse.OptionParser(version="%prog 0.1")
op.add_option("-u", "--username", help="Spotify username")
op.add_option("-p", "--password", help="Spotify password")
op.add_option("-v", "--verbose", help="Show debug information",
dest="verbose", action="store_true")
op.add_option("-b", "--album", help="Spotify Album ID")
(options, args) = op.parse_args()
if options.verbose:
logging.basicConfig(level=logging.DEBUG)
sessionM = sessionManager(options.username, options.password, True)
sessionM.connect()
你对我会忘记的事情有想法吗?