Skip to content

Instantly share code, notes, and snippets.

@metaory
Created May 31, 2025 14:01
Show Gist options
  • Save metaory/a00009d9d1ac0a1e7ca4c88ce464dab6 to your computer and use it in GitHub Desktop.
Save metaory/a00009d9d1ac0a1e7ca4c88ce464dab6 to your computer and use it in GitHub Desktop.
Spotify Playlist Download

Spotify Playlist Downloader

Downloads all tracks from a Spotify playlist as MP3s using spotDL.

Usage

  1. Export your Spotify API token:

    export SPOTIFY_TOKEN=your_token_here
  2. Run the script:

    bash spotlist.sh

Requires spotDL and jq installed.

#!/bin/bash
PLAYLIST_ID="XXXXXXXXXXXXXXXXX"
URL="https://api.spotify.com/v1/playlists/${PLAYLIST_ID}/tracks"
TOKEN="${SPOTIFY_TOKEN:?Missing SPOTIFY_TOKEN}"
FIELDS="items(track(name,artists))"
for cmd in spotdl jq curl; do
command -v $cmd > /dev/null || {
echo "$cmd is not installed"
exit 1
}
done
function fetch_more {
local offset=$1
res="$(curl -s "${URL}?fields=${FIELDS}&limit=50&offset=${offset}" -H "authorization: Bearer ${TOKEN}")"
jq -r '.items[] | "\(.track.artists[0].name) - \(.track.name)"' <<< "$res" >> output.txt
total=$(jq '.items|length' <<< "$res")
(( total )) && fetch_more $(( offset + 50 ))
}
fetch_more 0
while read -r item; do
echo "processing $item"
spotdl "$item"
done < output.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment