[GH-ISSUE #1097] Do the track IDs that spotipy fetches change over time? #654

Closed
opened 2026-02-28 00:00:34 +03:00 by kerem · 9 comments
Owner

Originally created by @JackDyre on GitHub (May 5, 2024).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1097

I am working on a project that stores files as spotify playlists. I made a lookup dictionary between 8194 (2^13 + 2) track ids that spotipy fetched, and 13 bit binary strings plus a lone 1 and 0. I had gotten it working, but today I am started getting a key error in my dict saying that one of the IDs was not a valid key.

The ID is saved in my dict must still be valid for adding tracks since the files/playlists that were giving me the key error were "uploaded" today

After some troubleshooting, i found that the ID that spotipy was currently fetching was '7jokkQ2OZEjngxvDbRzWPs' while the id that was fetched last week was '1lIkht1mUGFKnDQss3Qk6K'. Both of them link to the same song using open.spotify.com/track/id, but the new id link does not show that is liked while the old id link does. If they somehow are different instances of the same song, sending an add to playlist request using the old ID adds the new ID.

Does the ID that spotipy fetches change over time? What is going on here?

Originally created by @JackDyre on GitHub (May 5, 2024). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/1097 I am working on a project that stores files as spotify playlists. I made a lookup dictionary between 8194 (2^13 + 2) track ids that spotipy fetched, and 13 bit binary strings plus a lone 1 and 0. I had gotten it working, but today I am started getting a key error in my dict saying that one of the IDs was not a valid key. The ID is saved in my dict must still be valid for adding tracks since the files/playlists that were giving me the key error were "uploaded" today After some troubleshooting, i found that the ID that spotipy was currently fetching was '7jokkQ2OZEjngxvDbRzWPs' while the id that was fetched last week was '1lIkht1mUGFKnDQss3Qk6K'. Both of them link to the same song using open.spotify.com/track/id, but the new id link does not show that is liked while the old id link does. If they somehow are different instances of the same song, sending an add to playlist request using the old ID adds the new ID. Does the ID that spotipy fetches change over time? What is going on here?
kerem 2026-02-28 00:00:34 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@JackDyre commented on GitHub (May 5, 2024):

If the IDs change over time, it kinda ruins the whole project. Eventually I want to increase my list to 2^16 or even 2^17 track IDs and it wont be feasible to locate and update changed IDs with that many.

<!-- gh-comment-id:2094558320 --> @JackDyre commented on GitHub (May 5, 2024): If the IDs change over time, it kinda ruins the whole project. Eventually I want to increase my list to 2^16 or even 2^17 track IDs and it wont be feasible to locate and update changed IDs with that many.
Author
Owner

@chaffinched commented on GitHub (May 5, 2024):

They both appear to be the same track, one from the single release and the other from an EP (which admittedly appears to be the same as the single). You will often see the same for songs that are the same on the single and album release.

<!-- gh-comment-id:2094690523 --> @chaffinched commented on GitHub (May 5, 2024): They both appear to be the same track, one from the single release and the other from an EP (which admittedly appears to be the same as the single). You will often see the same for songs that are the same on the single and album release.
Author
Owner

@JackDyre commented on GitHub (May 5, 2024):

While it says single, the 'single' still has all of the songs from the EP.

That doesn't explain why spotipy is fetching a different ID than it did when I fetched all of the IDs last week to make the lookup dict.

I am adding songs to the playlist representing a file using the IDs I fetched originally, but when I fetch all the tracks in the playlist to read the file, it returns the new ID. Either the old ID somehow adds the new track, or it's the same track but the ID that gets fetched from it is different.

<!-- gh-comment-id:2094813559 --> @JackDyre commented on GitHub (May 5, 2024): While it says single, the 'single' still has all of the songs from the EP. That doesn't explain why spotipy is fetching a different ID than it did when I fetched all of the IDs last week to make the lookup dict. I am adding songs to the playlist representing a file using the IDs I fetched originally, but when I fetch all the tracks in the playlist to read the file, it returns the new ID. Either the old ID somehow adds the new track, or it's the same track but the ID that gets fetched from it is different.
Author
Owner

@dieser-niko commented on GitHub (May 5, 2024):

How exactly do you collect your IDs? What endpoint is your source?

<!-- gh-comment-id:2094935435 --> @dieser-niko commented on GitHub (May 5, 2024): How exactly do you collect your IDs? What endpoint is your source?
Author
Owner

@JackDyre commented on GitHub (May 5, 2024):

both now and when i collected the IDs originally, I used the playlist_tracks() method and iterate while increasing the offset until ['next'] is None

<!-- gh-comment-id:2094943506 --> @JackDyre commented on GitHub (May 5, 2024): both now and when i collected the IDs originally, I used the playlist_tracks() method and iterate while increasing the offset until ['next'] is None
Author
Owner

@JackDyre commented on GitHub (May 5, 2024):

Here is an example:

from main import api_request_manager

api_request_manager.add_tracks_to_playlist(
    playlist="https://open.spotify.com/playlist/4hnPJrn97HWmWg6h23q0Ht?si=8a8111bb71844681",
    tracks=["7jokkQ2OZEjngxvDbRzWPs", "1lIkht1mUGFKnDQss3Qk6K"],
)

y = api_request_manager.get_playlist_tracks(
    "https://open.spotify.com/playlist/4hnPJrn97HWmWg6h23q0Ht?si=8a8111bb71844681"
)

for n in y:
    print(n["id"])

api_request_manager is just a class that i wrote that slows down requests to 1 per second at the max and also handles the logic for splitting large numbers of track IDs into batchs for adding to playlists and iterating over the batches for fetching the tracks

That script returns

7jokkQ2OZEjngxvDbRzWPs
7jokkQ2OZEjngxvDbRzWPs

But originally when i fetched all the IDs for my lookup dict, it returned 1lIkht1mUGFKnDQss3Qk6K

<!-- gh-comment-id:2094949151 --> @JackDyre commented on GitHub (May 5, 2024): Here is an example: ```python from main import api_request_manager api_request_manager.add_tracks_to_playlist( playlist="https://open.spotify.com/playlist/4hnPJrn97HWmWg6h23q0Ht?si=8a8111bb71844681", tracks=["7jokkQ2OZEjngxvDbRzWPs", "1lIkht1mUGFKnDQss3Qk6K"], ) y = api_request_manager.get_playlist_tracks( "https://open.spotify.com/playlist/4hnPJrn97HWmWg6h23q0Ht?si=8a8111bb71844681" ) for n in y: print(n["id"]) ``` `api_request_manager` is just a class that i wrote that slows down requests to 1 per second at the max and also handles the logic for splitting large numbers of track IDs into batchs for adding to playlists and iterating over the batches for fetching the tracks That script returns ``` 7jokkQ2OZEjngxvDbRzWPs 7jokkQ2OZEjngxvDbRzWPs ``` But originally when i fetched all the IDs for my lookup dict, it returned `1lIkht1mUGFKnDQss3Qk6K`
Author
Owner

@dieser-niko commented on GitHub (May 5, 2024):

Ok wow, that's weird. If it bothers you, then it might help posting to the Spotify Community with your problem. But there's nothing that spotipy can fix about this.

<!-- gh-comment-id:2094951127 --> @dieser-niko commented on GitHub (May 5, 2024): Ok wow, that's weird. If it bothers you, then it might help posting to the [Spotify Community](https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer) with your problem. But there's nothing that spotipy can fix about this.
Author
Owner

@JackDyre commented on GitHub (May 5, 2024):

I think I figured out a solution, I can just store some sort of identifier string based of the track title and all of the artists and use that for when i convert the tracks back into binary because the that is very unlikely to change

<!-- gh-comment-id:2094958899 --> @JackDyre commented on GitHub (May 5, 2024): I think I figured out a solution, I can just store some sort of identifier string based of the track title and all of the artists and use that for when i convert the tracks back into binary because the that is very unlikely to change
Author
Owner

@dieser-niko commented on GitHub (May 9, 2024):

Closing as it seems that you found a solution

<!-- gh-comment-id:2103166932 --> @dieser-niko commented on GitHub (May 9, 2024): Closing as it seems that you found a solution
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#654
No description provided.