feat: dload full playlist

This commit is contained in:
2024-10-13 16:17:59 +02:00
parent f04325c3bd
commit 422d66d5b5
4 changed files with 81589 additions and 41901 deletions

25
spotify/get-tokens.sh Executable file
View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -eu
BEARER_TOKEN_RES=$(
curl -L https://open.spotify.com/ \
| grep 'id="session"' \
| sed 's&.*<script id="session"[^>]*>&&' \
| sed 's/<.*//'
)
BEARER_TOKEN=$(echo "$BEARER_TOKEN_RES" | jq -r .accessToken)
export BEARER_TOKEN
GUEST_TOKEN_RES=$(
curl -X POST https://clienttoken.spotify.com/v1/clienttoken \
-H "Accept: application/json" -H "content-type: application/json" \
--data '{"client_data":{"client_version":"1.2.27.147.g503c721c","client_id":"d8a5ed958d274c2e8ee717e6a4b0971d","js_sdk_data":{"device_brand":"unknown","device_model":"unknown","os":"linux","os_version":"unknown","device_id":"nuhuh","device_type":"computer"}}}'
)
if ! [[ "$(echo "$GUEST_TOKEN_RES" | jq -r .response_type)" == "RESPONSE_GRANTED_TOKEN_RESPONSE" ]]; then
printf "\x1b[1;31m%s\x1b[0m\n" 'Token response is NOT granted' >&2
exit 1;
fi
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
export TOKEN

81557
spotify/playlist.json Normal file

File diff suppressed because it is too large Load Diff

29
spotify/update-playlist.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eu
MYSELF=$(realpath "$0")
MYDIR=$(dirname "$MYSELF")
. "$MYDIR"/get-tokens.sh
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?)' > playlist.json
printf "downloaded %s songs metadata" "$(jq length playlist.json)"