fix: patch spotify token, manual scrape for now
This commit is contained in:
parent
546d645a0e
commit
bd8b0c3cca
@ -1,25 +1,43 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
BEARER_TOKEN_RES=$(
|
if [[ -z "${BEARER_TOKEN:-}" ]]; then
|
||||||
|
printf "Atempting to scrape a bearer token...\n"
|
||||||
|
|
||||||
|
BEARER_TOKEN_RES=$(
|
||||||
curl -sL https://open.spotify.com/ \
|
curl -sL https://open.spotify.com/ \
|
||||||
| grep 'id="session"' \
|
| grep 'id="session"' \
|
||||||
| sed 's&.*<script id="session"[^>]*>&&' \
|
| sed 's&.*<script id="session"[^>]*>&&' \
|
||||||
| sed 's/<.*//'
|
| sed 's/<.*//'
|
||||||
)
|
)
|
||||||
BEARER_TOKEN=$(echo "$BEARER_TOKEN_RES" | jq -r .accessToken)
|
BEARER_TOKEN=$(echo "$BEARER_TOKEN_RES" | jq -r .accessToken)
|
||||||
export BEARER_TOKEN
|
|
||||||
|
|
||||||
GUEST_TOKEN_RES=$(
|
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 \
|
curl -sX POST https://clienttoken.spotify.com/v1/clienttoken \
|
||||||
-H "Accept: application/json" -H "content-type: application/json" \
|
-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"}}}'
|
--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
|
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
|
printf "\x1b[1;31m%s\x1b[0m\n" 'Token response is NOT granted' >&2
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
|
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
|
||||||
export 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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user