fix: patch spotify token, manual scrape for now

This commit is contained in:
javalsai 2025-03-17 18:50:37 +01:00
parent 546d645a0e
commit bd8b0c3cca
Signed by: javalsai
SSH Key Fingerprint: SHA256:3G83yKhBUWVABVX/vPWH88xnK4+ptMtHkZGCRXD4Mk8

View File

@ -1,6 +1,9 @@
#!/usr/bin/env bash
set -eu
if [[ -z "${BEARER_TOKEN:-}" ]]; then
printf "Atempting to scrape a bearer token...\n"
BEARER_TOKEN_RES=$(
curl -sL https://open.spotify.com/ \
| grep 'id="session"' \
@ -8,8 +11,16 @@ BEARER_TOKEN_RES=$(
| sed 's/<.*//'
)
BEARER_TOKEN=$(echo "$BEARER_TOKEN_RES" | jq -r .accessToken)
export BEARER_TOKEN
if [[ -z "${BEARER_TOKEN:-}" ]]; then
printf "ERR: Failed to get a bearer token, pass one with \$BEARER_TOKEN\n" >&2
exit 1
fi
export BEARER_TOKEN
fi
if [[ -z "${TOKEN:-}" ]]; then
printf "Atempting to get a token with the bearer one...\n"
GUEST_TOKEN_RES=$(
curl -sX POST https://clienttoken.spotify.com/v1/clienttoken \
-H "Accept: application/json" -H "content-type: application/json" \
@ -22,4 +33,11 @@ if ! [[ "$(echo "$GUEST_TOKEN_RES" | jq -r .response_type)" == "RESPONSE_GRANTED
fi
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
if [[ -z "${BEARER_TOKEN:-}" ]]; then
printf "ERR: Failed to get a normal token, pass one with \$TOKEN\n" >&2
exit 1
fi
export TOKEN
fi