def success():
token1 = session["TOKEN1"]
token2 = session["TOKEN2"]
access_token1 = token1["access_token"]
access_token2 = token2["access_token"]
session.clear()
intersection_songs = INTERSECTION_DICT[access_token1 + "_" + access_token2]
del INTERSECTION_DICT[access_token1 + "_" + access_token2]
sp1 = spotipy.Spotify(auth=access_token1)
sp2 = spotipy.Spotify(auth=access_token2)
user_id1 = sp1.me()["id"]
user_id2 = sp2.me()["id"]
playlist_name = 'Compatify-' + user_id1 + '-' + user_id2
new_playlist1 = sp1.user_playlist_create(user_id1, playlist_name, public=False)
new_playlist2 = sp2.user_playlist_create(user_id2, playlist_name, public=False)
size = len(intersection_songs)
index = 0
while True:
current_num = size - index
if current_num > 100:
sp1.user_playlist_add_tracks(user_id1, new_playlist1["id"], intersection_songs[index:index+100], position=None)
sp2.user_playlist_add_tracks(user_id2, new_playlist2["id"], intersection_songs[index:index+100], position=None)
index += 100
elif current_num > 0:
sp1.user_playlist_add_tracks(user_id1, new_playlist1["id"], intersection_songs[index:index+current_num], position=None)
sp2.user_playlist_add_tracks(user_id2, new_playlist2["id"], intersection_songs[index:index+current_num], position=None)
break
else:
break
return render_template("success.html")
# Methods
评论列表
文章目录