Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alexanderscott/042601a4e68342ac580716f890150c01 to your computer and use it in GitHub Desktop.
Save alexanderscott/042601a4e68342ac580716f890150c01 to your computer and use it in GitHub Desktop.
Get Spotify track URIs from playlist URI
# Spotify's desktop UI no longer allows you to copy to clipboard all track URIs for a playlist
# Script taken from https://github.com/hbashton/spotify-ripper/issues/61
# Requirements: python v2, spotipy (can be install from pip)
# Usage: First go to Spotify developer page and create a new app for client_id and client_secret
# export SPOTIPY_CLIENT_ID=<your_client_id>
# export SPOTIPY_CLIENT_SECRET=<your_client_secret>
# python spotify_get_playlist_track_uris.py <playlist-uri>
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
import sys
def get_offset():
results = sp.playlist_tracks(playlist_id, offset=0, fields='total')
total = results["total"]
return total
def get_track_uri(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__':
playlist_uri = sys.argv[1]
client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
playlist_id = playlist_uri
for x in range(get_offset()):
tracks = get_track_uri(x)
for y in tracks:
print y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment