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

downloading playlists #61

Open
pfandipfandautomat opened this issue Apr 23, 2020 · 4 comments
Open

downloading playlists #61

pfandipfandautomat opened this issue Apr 23, 2020 · 4 comments

Comments

@pfandipfandautomat
Copy link

Hey,

is there a workaround for downloading playlists?
The actual spotify uri format for playlists is: spotify:playlist:0SyciLmBQVD3POK0jTD4BW

but the format spotify-ripper wants is like this: spotify:user:username:playlist:4vkGNcsS8lRXj4q945NIA4

thanks in advance

@pfandipfandautomat
Copy link
Author

after some research, I've found out that spotify changed the API for playlists in 2018: https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/

and after some more digging, I've found out that the handling of the uris is being done by libspotify, which is deprecated.

Unfortunatly my python is not the best, but I might ask someone I know who could maybe help to fix the handling of the spotify playlist uris. Doesn't seem too complicated

@pfandipfandautomat
Copy link
Author

pfandipfandautomat commented Apr 25, 2020

With the help of Spotipy (https://github.com/plamere/spotipy), I've created a little script, which returns the track uris of a playlist. It's a fine workaround for me right now, I just paste the track uris into a file, and let spotify-ripper do the rest.

from spotipy.oauth2 import SpotifyClientCredentials
import spotipy

def getOffset():
    results= sp.playlist_tracks(playlist_id, offset=0, fields='total')
    total = results["total"]
    return total

def getTrackURI(offset):
    results = sp.playlist_tracks(playlist_id, offset=offset, limit=1, fields='items.track.uri')
    tracks = []
    for item in results["items"]:
        tracks.append(item["track"]["uri"])
    return tracks



if __name__ == '__main__':

    client_credentials_manager = SpotifyClientCredentials()
    sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

    playlist_id = 'spotify:playlist:45eABbQmeehl9auEpxwNDo'

    for x in range(getOffset()):
       tracks = getTrackURI(x)
       for y in tracks:
           print y


@enkoder
Copy link

enkoder commented Aug 23, 2021

@arthurkoch your code doesn't account for a large playlist, you'll need to handle the case where the number of tracks exceeds the limit. This code will continue to hit the API until there are no more in the playlist.

def get_track_uris_from_playlist(playlist_uri):
    client = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
    track_uris = []

    # initial fetch
    results = client.playlist_tracks(playlist_uri, limit=100)
    for track in results['items']:
        track_uris.append(track['track']['uri'])

    # pagination next calls
    while results and results['next']:
        results = client.next(results)
        for track in results['items']:
            track_uris.append(track['track']['uri'])

    return track_uris

@pfandipfandautomat
Copy link
Author

@enkoder Currently I'm using https://github.com/kmille/deezer-downloader, which is working very well. It also accepts Spotify Playlists.

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

2 participants