30 lines
732 B
Bash
Executable File
30 lines
732 B
Bash
Executable File
#!/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" "$(jq length playlist.json)"
|