Downloads all tracks from a Spotify playlist as MP3s using spotDL.
-
Export your Spotify API token:
export SPOTIFY_TOKEN=your_token_here -
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 |