#!/usr/bin/env bash set -eu MYSELF=$(realpath "$0") MYDIR=$(dirname "$MYSELF") . "$MYDIR"/get-tokens.sh PLAYLIST_ID=${PLAYLIST_ID:-"2BoXyJeV0fhEHOy4uiByxr"} i=0 iter_url=https://api.spotify.com/v1/playlists/$PLAYLIST_ID/tracks while :; do RES=$(curl --request GET \ --url "$iter_url" \ --header 'Authorization: Bearer '"$BEARER_TOKEN" \ --header 'client-token: '"$TOKEN" 2> /dev/null) iter_url=$(jq -r .next <<< "$RES") echo "$RES" i=$((i+1)) [[ "$iter_url" == "null" ]] && break done \ | pv \ | jq .items \ | jq -s 'reduce .[] as $x ([]; . + $x)' \ | jq 'del(.. | .available_markets?, .added_by?, .popularity?)' > playlist.json printf "downloaded %s songs metadata\n" "$(jq length playlist.json)" jq -r '.[].track | ( .name + " - " + (.album.artists | map(.name) | join(", ")) )' playlist.json \ > playlist.txt printf "and dumped it as text on %s\n" playlist.txt jq -c '.[].track | ( [.id, .name, .album.name, (.album.artists | map(.name))] )' playlist.json \ > summary-playlist.json printf "AND dumped summary metadata on %s\n" summary-playlist.txt