mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-27 16:45:52 +03:00
[GH-ISSUE #601] Avoid duplicate tracks on a playlist #359
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#359
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AlexandreAguido on GitHub (Oct 31, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/601
This is an awesome project, it saved me hours on coverting a radio history to a playlist,
but I did not find a way to avoid adding duplicate tracks to a playlist. I think that a native option to avoid duplicate
tracks on a playlist would be nice
@stephanebruckert commented on GitHub (Oct 31, 2020):
I agree, ideally the API would allow this https://github.com/spotify/web-api/issues/118, but it's closed as wont-fix.
The current recommended practice is that each app keeps tracks of the current tracks in a playlist, and check whether it's already there before inserting.
Unfortunately, it could be hard to do this in the library, because we don't know in advance how to persist the current playlist tracks (what DB? what structure?). The next option would be to retrieve the full playlist every time we call
add_track_to_playlist(), but that could be misused and lead to poor performance (a playlist can have up to 11k tracks).I'm going to keep this open for a bit in case someone can suggest a good solution, otherwise we will likely close it. Also keeping in mind that spotipy is "light weight".
@Peter-Schorn commented on GitHub (Nov 1, 2020):
One suggestion I have is to cache the
snapshot_idof a playlist, which changes each time the playlist changes. Think of it as like a hash code. This prevents you from having to retrieve all of the tracks in a playlist to see if it has changed. See https://developer.spotify.com/documentation/general/guides/working-with-playlists/#version-control-and-snapshotsYou can use the following to retrieve just the snapshot id of a playlist:
@stephanebruckert commented on GitHub (Nov 1, 2020):
@Peter-Schorn isn't the
snapshot_idchanging even when a duplicate is added?@Peter-Schorn commented on GitHub (Nov 1, 2020):
Yes, it will change even if a duplicate is added. And, even if you add a track and then remove that same track, the snapshot id will still change to a unique value each time. However, if the user hasn't modified the playlist at all, then this parameter can still be useful for avoiding retrieving all of the tracks again. Admittedly, this isn't a direct solution to @AlexandreAguido 's question, but I thought it would still be worth mentioning.
@AlexandreAguido commented on GitHub (Nov 1, 2020):
Well I opened this issue because I thought that the spotify api could easily handle the option to add or avoid duplicate songs, but sadly they don't support it.
A way to manage it without depending of spotify api would be to keep track of the ids for each track in the playlist and the snapshot_id then check if the snapshot_id changed before downloading the playlist info and finally check with tracks don't belong to a playlist before insert them. But for a web app with hundreds of users that depends of this project it will increase significantly the resouce usage (space, bandwith, and CPU resource for the search operations) breaking the purpose of this project to be a "lightweight"
I say leave it as it is and hope that something like this https://github.com/spotify/web-api/issues/444 be implemented quickly.
@stephanebruckert commented on GitHub (Nov 1, 2020):
yep... closing then. Thanks for reporting though, I share the idea.