You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 20:50:19