Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_playlist_items adds a different videoId than the one provided #674

Open
srajangarg opened this issue Nov 6, 2024 · 1 comment
Open

Comments

@srajangarg
Copy link

srajangarg commented Nov 6, 2024

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
@srajangarg
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant