私はこれを持ってfunction
いますSpotify
。
#a function to play Spotify
def play(id_):
print 'playing', id_
os.system("osascript -e 'tell application \"Spotify\" to play track \"%s\"'" % (id_,))
そして、すべての曲loop
を反復処理する次の は、すべての再生可能な ( ) を取得し、それらをに渡します。playlist
id
foreign_id
play(id_)
duration
各曲をに渡して、time.sleep()
各曲が終了するまでループを停止し、ループをもう一度繰り返します。
for i, song in enumerate(song_playlist):
#we need to track each song id
song_id = song_playlist[i]['id']
#in order to get song 'duration', access 'song/profile response' and pass the id as an argument
response_profile = en.get('song/profile', id=song_id, bucket="audio_summary")
song_profile = response_profile['songs']
dur = song_profile[0]['audio_summary']['duration']
#convert to miliseconds
dur *= 1000
print int(round(dur))
#now we access each song 'foreign_id'
for track in song:
track = song['tracks'][i]
track_id = track['foreign_id'].replace('-WW', '')
print '{0} {2} {1}'.format(i, song['artist_name'], song['title'])
#call the function for each track
play(track_id) #CALL FUNCTION HERE
time.sleep(int(round(dur))) # SET INTERVAL CALL TO EACH SONG DURATION
ただし、再生されるのは 1 曲だけであり、再帰は消滅します。
コードを一度だけ実行して、すべてのトラックを順番に再生する機能を持たせるには、どうすればコードを修正できますか?