コード例 #1
0
ファイル: test.py プロジェクト: geel9/spotify-websocket-api
def track_uri_callback(sp, result):
	global currentLid, currentTracks, currentTrackI, currentPlaylistId
	if "type" in result and result["type"] == 3:
		Logging.notice("Track is not available. Skipping.")
		do_next_queue(sp)
		return

	#We need to "end" the previous track
	if currentTrackI > 0:	
		#Get the last track
		currentTrack = currentTracks[currentTrackI - 1]
		trackUri = SpotifyUtil.id2uri("track", SpotifyUtil.gid2id(currentTrack.gid))
		sp.track_end(currentLid, 0, 97, trackUri, sp.username, currentPlaylistId, None)

	currentTrack = currentTracks[currentTrackI]
	trackUri = SpotifyUtil.id2uri("track", SpotifyUtil.gid2id(currentTrack.gid))

	lid = result["lid"]
	url = result["uri"]
	currentLid = lid

	print "Got URL for: " + currentTrack.name + " - " + currentTrack.artist[0].name

	sp.track_event(lid, 3, 0, None)
	sp.track_progress(lid, 500, 97, sp.username, currentPlaylistId, trackUri, None)
	sp.track_event(lid, 4, 500, None)
	sp.send_command("sp/echo", ["h"])
	sp.send_command("sp/log", [30, 1, "heartbeat", 77, 77, 2, False])	
	time.sleep(1)
	do_next_queue(sp)