linsomniac/spotify_to_ytmusic

Unable to backup spotify playlists

Closed this issue · 7 comments

Platform : Windows

Spotify logged in successfully

Starting backup...
Logging in (click if it doesn't open automatically): https://accounts.spotify.com/authorize?response_type=token&client_id=5c098bcc800e45d49e476265bc9b6934&scope=playlist-read-private+playlist-read-collaborative+user-library-read&redirect_uri=http%3A%2F%2F127.0.0.1%3A43019%2Fredirect
Received access token from Spotify: XXXXXXXXXXXXXX
Loading user info...
Logged in as xxxxxxxxxxxxx(xxxxxxxxxxxxxxxxxx)
Loading liked albums and songs...
Couldn't load URL: https://api.spotify.com/v1/users/xxxxxxxxxxxxxxx/tracks?limit=50 (HTTP Error 404: Not Found)
Trying again...
Couldn't load URL: https://api.spotify.com/v1/users/xxxxxxxxxxxxxxx/tracks?limit=50 (HTTP Error 404: Not Found)
Trying again...
Couldn't load URL: https://api.spotify.com/v1/users/xxxxxxxxxxxxxxx/tracks?limit=50 (HTTP Error 404: Not Found)
Trying again...

Not sure If I missed a step here
YT Music logged in successfully too

Found the issue - spotify's API has changed?

The script calls https://api.spotify.com/v1/users/(yourUserName)/tracks whereas the spotify API reference (https://developer.spotify.com/documentation/web-api/reference/get-users-saved-tracks) uses https://api.spotify.com/v1/me/tracks

It might also be a privacy issue now that I think about it, maybe I've disallowed others to access my playlists.

If you go to spotify2ytmusic/lib/python3.12/site-packages/spotify2ytmusic and change it like so, it works:

....
    user_id_escaped = "me" #urllib.parse.quote(me["id"])
    playlists = []
    liked_albums = []

    # List liked albums and songs
    if "liked" in dump:
        print("Loading liked albums and songs...")
        liked_tracks = spotify.list(
            "{user_id}/tracks".format(user_id=user_id_escaped), {"limit": 50}
        )
        liked_albums = spotify.list("me/albums", {"limit": 50})
        playlists += [{"name": "Liked Songs", "tracks": liked_tracks}]

    # List all playlists and the tracks in each playlist
    if "playlists" in dump:
        print("Loading playlists...")
        playlist_data = spotify.list(
            "{user_id}/playlists".format(user_id=user_id_escaped), {"limit": 50}
        )
....

I have this same issue but for Platform: Mac. Any suggestions on fixing?

Same problem cant seem to fix it

Found the issue - spotify's API has changed?

The script calls https://api.spotify.com/v1/users/(yourUserName)/tracks whereas the spotify API reference (https://developer.spotify.com/documentation/web-api/reference/get-users-saved-tracks) uses https://api.spotify.com/v1/me/tracks

It might also be a privacy issue now that I think about it, maybe I've disallowed others to access my playlists.

If you go to spotify2ytmusic/lib/python3.12/site-packages/spotify2ytmusic and change it like so, it works:

....
    user_id_escaped = "me" #urllib.parse.quote(me["id"])
    playlists = []
    liked_albums = []

    # List liked albums and songs
    if "liked" in dump:
        print("Loading liked albums and songs...")
        liked_tracks = spotify.list(
            "{user_id}/tracks".format(user_id=user_id_escaped), {"limit": 50}
        )
        liked_albums = spotify.list("me/albums", {"limit": 50})
        playlists += [{"name": "Liked Songs", "tracks": liked_tracks}]

    # List all playlists and the tracks in each playlist
    if "playlists" in dump:
        print("Loading playlists...")
        playlist_data = spotify.list(
            "{user_id}/playlists".format(user_id=user_id_escaped), {"limit": 50}
        )
....

Thanks, this worked for me.

To clarify for anyone else, you'll need to navigate to this path: /site-packages/spotify2ytmusic

Edit this file, I used notepad++: spotify_backup.py

Find and jump to the line: user_id_escaped = "me" #urllib.parse.quote(me["id"])

Replace with the code quoted above

Found the issue - spotify's API has changed?

The script calls https://api.spotify.com/v1/users/(yourUserName)/tracks whereas the spotify API reference (https://developer.spotify.com/documentation/web-api/reference/get-users-saved-tracks) uses https://api.spotify.com/v1/me/tracks

It might also be a privacy issue now that I think about it, maybe I've disallowed others to access my playlists.

If you go to spotify2ytmusic/lib/python3.12/site-packages/spotify2ytmusic and change it like so, it works:

....
    user_id_escaped = "me" #urllib.parse.quote(me["id"])
    playlists = []
    liked_albums = []

    # List liked albums and songs
    if "liked" in dump:
        print("Loading liked albums and songs...")
        liked_tracks = spotify.list(
            "{user_id}/tracks".format(user_id=user_id_escaped), {"limit": 50}
        )
        liked_albums = spotify.list("me/albums", {"limit": 50})
        playlists += [{"name": "Liked Songs", "tracks": liked_tracks}]

    # List all playlists and the tracks in each playlist
    if "playlists" in dump:
        print("Loading playlists...")
        playlist_data = spotify.list(
            "{user_id}/playlists".format(user_id=user_id_escaped), {"limit": 50}
        )
....

THank you it worked for me aswell, it just took me ages to find the file to edit, not the most savvy with this python stuff :)

Found the issue - spotify's API has changed?

The script calls https://api.spotify.com/v1/users/(yourUserName)/tracks whereas the spotify API reference (https://developer.spotify.com/documentation/web-api/reference/get-users-saved-tracks) uses https://api.spotify.com/v1/me/tracks

It might also be a privacy issue now that I think about it, maybe I've disallowed others to access my playlists.

If you go to spotify2ytmusic/lib/python3.12/site-packages/spotify2ytmusic and change it like so, it works:

....
    user_id_escaped = "me" #urllib.parse.quote(me["id"])
    playlists = []
    liked_albums = []

    # List liked albums and songs
    if "liked" in dump:
        print("Loading liked albums and songs...")
        liked_tracks = spotify.list(
            "{user_id}/tracks".format(user_id=user_id_escaped), {"limit": 50}
        )
        liked_albums = spotify.list("me/albums", {"limit": 50})
        playlists += [{"name": "Liked Songs", "tracks": liked_tracks}]

    # List all playlists and the tracks in each playlist
    if "playlists" in dump:
        print("Loading playlists...")
        playlist_data = spotify.list(
            "{user_id}/playlists".format(user_id=user_id_escaped), {"limit": 50}
        )
....

I was on the same track after I saw their API docs.
The issue is with their "Liked songs" related logic which didn't matter to me as I only wanted to copy playlists that I created.
I found another workaround by using the CLI and only exporting playlists (instead of the default option which is "liked,playlists"

Thanks @fortytwoish for helping out!
A PR with your changes might be great if you are inclined to do it.

Yup API has changed. Worked after changing the URL in the source.