[GH-ISSUE #674] add_playlist_items adds a different videoId than the one provided #446

Closed
opened 2026-02-27 23:00:49 +03:00 by kerem · 2 comments
Owner

Originally created by @srajangarg on GitHub (Nov 6, 2024).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/674

Describe the bug
On adding some videoId to a playlist, I notice some other version of the song (with a different videoId) is added instead

To Reproduce
script to illustrate bug

from ytmusicapi import YTMusic
ytmusic = YTMusic("oauth.json")


def get_or_create_playlist_by_name(name: str):
    my_playlists = ytmusic.get_library_playlists(limit=None)
    playlist = next((playlist for playlist in my_playlists if playlist['title'] == name), None)
    
    if playlist is None:
        playlistId = ytmusic.create_playlist(name, description="")
    else:
        playlistId = playlist['playlistId']
    
    playlist_details = ytmusic.get_playlist(playlistId, limit=None)
    return playlist_details

def print_playlist_songs(playlist_name: str):
    playlist = get_or_create_playlist_by_name(playlist_name)
    print(f"Playlist {playlist_name} has {len(playlist['tracks'])} song(s)")
    for song in playlist['tracks']:
        print(song['videoId'])
    print()

def add_song_to_playlist(playlist_name: str, song_id: str):
    print(f"Adding song {song_id} to playlist {playlist_name}\n")
    playlist = get_or_create_playlist_by_name(playlist_name)
    response = ytmusic.add_playlist_items(playlist['id'], [song_id])
    print(f"{response}\n")

# print empty playlist
print_playlist_songs("dummy")

# # add song to playlist and print again
add_song_to_playlist("dummy", "XMNiZfeCmeo")
print_playlist_songs("dummy")

prints

Playlist dummy has 0 song(s)

Adding song XMNiZfeCmeo to playlist dummy

{'status': 'STATUS_SUCCEEDED', 'playlistEditResults': [{'videoId': 'XMNiZfeCmeo', 'setVideoId': '289F4A46DF0A30D2', 'multiSelectData': {'multiSelectParams': 'CAESIlBMMkV3c2xMLVllSFJJOWtCcWtUblpRS2dnc0JuRzVjSDc=', 'multiSelectItem': 'Ch8KC1hNTmlaZmVDbWVvEhAyODlGNEE0NkRGMEEzMEQy'}}]}

Playlist dummy has 1 song(s)
-RL5QBdlacQ
Originally created by @srajangarg on GitHub (Nov 6, 2024). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/674 **Describe the bug** On adding some `videoId` to a playlist, I notice some other version of the song (with a different `videoId`) is added instead **To Reproduce** script to illustrate bug ```python from ytmusicapi import YTMusic ytmusic = YTMusic("oauth.json") def get_or_create_playlist_by_name(name: str): my_playlists = ytmusic.get_library_playlists(limit=None) playlist = next((playlist for playlist in my_playlists if playlist['title'] == name), None) if playlist is None: playlistId = ytmusic.create_playlist(name, description="") else: playlistId = playlist['playlistId'] playlist_details = ytmusic.get_playlist(playlistId, limit=None) return playlist_details def print_playlist_songs(playlist_name: str): playlist = get_or_create_playlist_by_name(playlist_name) print(f"Playlist {playlist_name} has {len(playlist['tracks'])} song(s)") for song in playlist['tracks']: print(song['videoId']) print() def add_song_to_playlist(playlist_name: str, song_id: str): print(f"Adding song {song_id} to playlist {playlist_name}\n") playlist = get_or_create_playlist_by_name(playlist_name) response = ytmusic.add_playlist_items(playlist['id'], [song_id]) print(f"{response}\n") # print empty playlist print_playlist_songs("dummy") # # add song to playlist and print again add_song_to_playlist("dummy", "XMNiZfeCmeo") print_playlist_songs("dummy") ``` prints ``` Playlist dummy has 0 song(s) Adding song XMNiZfeCmeo to playlist dummy {'status': 'STATUS_SUCCEEDED', 'playlistEditResults': [{'videoId': 'XMNiZfeCmeo', 'setVideoId': '289F4A46DF0A30D2', 'multiSelectData': {'multiSelectParams': 'CAESIlBMMkV3c2xMLVllSFJJOWtCcWtUblpRS2dnc0JuRzVjSDc=', 'multiSelectItem': 'Ch8KC1hNTmlaZmVDbWVvEhAyODlGNEE0NkRGMEEzMEQy'}}]} Playlist dummy has 1 song(s) -RL5QBdlacQ ```
kerem 2026-02-27 23:00:49 +03:00
  • closed this issue
  • added the
    invalid
    label
Author
Owner

@srajangarg commented on GitHub (Nov 7, 2024):

i just ran it again and it's working now?

Playlist dummy has 0 song(s)

Adding song XMNiZfeCmeo to playlist dummy

{'status': 'STATUS_SUCCEEDED', 'playlistEditResults': [{'videoId': 'XMNiZfeCmeo', 'setVideoId': '56B44F6D10557CC6', 'multiSelectData': {'multiSelectParams': 'CAESIlBMMkV3c2xMLVllSFJybm50dTJBMUhXaU03blZJazR4YXQ=', 'multiSelectItem': 'Ch8KC1hNTmlaZmVDbWVvEhA1NkI0NEY2RDEwNTU3Q0M2'}}]}

Playlist dummy has 1 song(s)
XMNiZfeCmeo

im so confused by this non-deterministic behaviour. not sure what changed

<!-- gh-comment-id:2461473211 --> @srajangarg commented on GitHub (Nov 7, 2024): i just ran it again and it's working now? ``` Playlist dummy has 0 song(s) Adding song XMNiZfeCmeo to playlist dummy {'status': 'STATUS_SUCCEEDED', 'playlistEditResults': [{'videoId': 'XMNiZfeCmeo', 'setVideoId': '56B44F6D10557CC6', 'multiSelectData': {'multiSelectParams': 'CAESIlBMMkV3c2xMLVllSFJybm50dTJBMUhXaU03blZJazR4YXQ=', 'multiSelectItem': 'Ch8KC1hNTmlaZmVDbWVvEhA1NkI0NEY2RDEwNTU3Q0M2'}}]} Playlist dummy has 1 song(s) XMNiZfeCmeo ``` im so confused by this non-deterministic behaviour. not sure what changed
Author
Owner

@sigma67 commented on GitHub (Dec 17, 2024):

@srajangarg please report back again if you can reproduce it reliably

<!-- gh-comment-id:2549336016 --> @sigma67 commented on GitHub (Dec 17, 2024): @srajangarg please report back again if you can reproduce it reliably
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/ytmusicapi#446
No description provided.