Compare commits

...

15 Commits

5 changed files with 18061 additions and 1204 deletions

View File

@@ -1,25 +1,43 @@
#!/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
if [[ -z "${BEARER_TOKEN:-}" ]]; then
printf "Atempting to scrape a bearer token...\n"
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"}}}'
)
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

File diff suppressed because it is too large Load Diff

1266
spotify/playlist.txt Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -6,8 +6,17 @@ MYDIR=$(dirname "$MYSELF")
. "$MYDIR"/get-tokens.sh
PLAYLIST_ID=${PLAYLIST_ID:-"2BoXyJeV0fhEHOy4uiByxr"}
TARGET=${TARGET:-}
if [ -z "$TARGET" ]; then
printf '\x1b[1;33m%s\x1b[0m\n' "W: No \$TARGET specified, using CWD"
TARGET=.
fi
i=0
PLAYLIST_JSON="$TARGET/playlist.json"
PLAYLIST_TXT="$TARGET/playlist.txt"
SUM_PLAYLIST_JSON="$TARGET/summary-playlist.json"
# i=0
iter_url=https://api.spotify.com/v1/playlists/$PLAYLIST_ID/tracks
while :; do
RES=$(curl --request GET \
@@ -18,12 +27,26 @@ while :; do
iter_url=$(jq -r .next <<< "$RES")
echo "$RES"
i=$((i+1))
# _=$((i++))
[[ "$iter_url" == "null" ]] && break
done \
| pv \
| jq .items \
| jq -s 'reduce .[] as $x ([]; . + $x)' \
| jq 'del(.. | .available_markets?, .added_by?, .popularity?)' > playlist.json
| jq 'del(.. | .available_markets?, .added_by?, .popularity?)' > "$PLAYLIST_JSON"
printf "downloaded %s songs metadata" "$(jq length playlist.json)"
ARR=" "$'\x1b'"[32m=>"$'\x1b'"[0m"
printf "$ARR downloaded \x1b[33m%s\x1b[0m songs metadata at \x1b[35m%s\x1b[0m\n" \
"$(jq length "$PLAYLIST_JSON")" "$PLAYLIST_JSON"
jq -r '.[].track | ( .name + " - " + (.album.artists | map(.name) | join(", ")) )' "$PLAYLIST_JSON" \
> "$PLAYLIST_TXT"
printf "$ARR dumped it as text on \x1b[35m%s\x1b[0m\n" "$PLAYLIST_TXT"
jq -c '.[].track | ( [.id, .name, .album.name, (.album.artists | map(.name))] )' "$PLAYLIST_JSON" \
> "$SUM_PLAYLIST_JSON"
printf "$ARR dumped summary metadata on \x1b[35m%s\x1b[0m\n" "$SUM_PLAYLIST_JSON"
printf "Dupped Songs:\n"
sort < "$PLAYLIST_TXT" | uniq -d