feat: dload full playlist
This commit is contained in:
parent
f04325c3bd
commit
422d66d5b5
41891
playlist.json
41891
playlist.json
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
PLAYLIST_ID="2BoXyJeV0fhEHOy4uiByxr"
|
||||
|
||||
BEARER_TOKEN_RES=$(
|
||||
curl -L https://open.spotify.com/playlist/"$PLAYLIST_ID" \
|
||||
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 \
|
||||
@ -23,10 +22,4 @@ if ! [[ "$(echo "$GUEST_TOKEN_RES" | jq -r .response_type)" == "RESPONSE_GRANTED
|
||||
fi
|
||||
|
||||
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
|
||||
echo "got bearer token $BEARER_TOKEN" >&2
|
||||
echo "got token $TOKEN" >&2
|
||||
|
||||
curl --request GET \
|
||||
--url https://api.spotify.com/v1/playlists/"$PLAYLIST_ID"/tracks \
|
||||
--header 'Authorization: Bearer '"$BEARER_TOKEN" \
|
||||
--header 'client-token: '"$TOKEN" | jq > playlist.json
|
||||
export TOKEN
|
81557
spotify/playlist.json
Normal file
81557
spotify/playlist.json
Normal file
File diff suppressed because it is too large
Load Diff
29
spotify/update-playlist.sh
Executable file
29
spotify/update-playlist.sh
Executable 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)"
|
Loading…
x
Reference in New Issue
Block a user