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,25 +1,43 @@
#!/usr/bin/env bash
set -eu
BEARER_TOKEN_RES=$(
curl -sL 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
if [[ -z "${BEARER_TOKEN:-}" ]]; then
printf "Atempting to scrape a bearer token...\n"
GUEST_TOKEN_RES=$(
curl -sX POST https://clienttoken.spotify.com/v1/clienttoken \
-H "Accept: application/json" -H "content-type: application/json" \
--data '{"client_data":{"client_version":"1.2","client_id":"d8a5ed958d274c2e8ee717e6a4b0971d","js_sdk_data":{"device_brand":"unknown","device_model":"unknown","os":"unknown","os_version":"unknown","device_id":"unknown","device_type":"unknown"}}}'
)
BEARER_TOKEN_RES=$(
curl -sL https://open.spotify.com/ \
| grep 'id="session"' \
| sed 's&.*<script id="session"[^>]*>&&' \
| sed 's/<.*//'
)
BEARER_TOKEN=$(echo "$BEARER_TOKEN_RES" | jq -r .accessToken)
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;
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
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
export TOKEN
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" \
--data '{"client_data":{"client_version":"1.2","client_id":"d8a5ed958d274c2e8ee717e6a4b0971d","js_sdk_data":{"device_brand":"unknown","device_model":"unknown","os":"unknown","os_version":"unknown","device_id":"unknown","device_type":"unknown"}}}'
)
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)
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