Spotipy playlist_remove_all_occurrences_of_items仅部分分支生效问题求助
Spotify播放列表删除歌曲问题
以下是用于删除播放列表中当前/最近播放歌曲的代码:
currently_playing = sp.current_user_playing_track() time_elapsed = currently_playing['progress_ms'] / 1000 / 60 try: if time_elapsed < 0.5: last_song_played = sp.current_user_recently_played(1) sp.playlist_remove_all_occurrences_of_items(playlist_id=playlisturi, items={last_song_played['items'][0]['track']['uri']}) else: sp.playlist_remove_all_occurrences_of_items(playlist_id=playlisturi, items={currently_playing['item']['uri']})
playlist_remove_all_occurrences_of_items()方法在else分支可正常删歌,但if分支执行后歌曲并未被删除。调试显示两个分支都收到了Spotify返回的200响应码,仅else分支操作有效。
*编辑:
已定位疑似原因:若待删除歌曲播放时长过短(推测),current_user_recently_played接口不会更新,导致代码尝试删除的是已经被移除过的曲目,接口返回“成功”但实际无操作;若完整播放歌曲,该接口会正常更新。测试时因快速跳过歌曲(仅播放几秒),触发了这个问题。
内容的提问来源于stack exchange,提问作者Limgedamm
相关产品推荐
相关产品推荐

