Compare commits
15 Commits
1eadb44490
...
master
Author | SHA1 | Date | |
---|---|---|---|
6f37b5f9b4
|
|||
3d360a41f7
|
|||
bd8b0c3cca
|
|||
546d645a0e
|
|||
c63dd8a7d3
|
|||
8ec3192f0d
|
|||
cf2486f549
|
|||
dbeb324937
|
|||
9be553d370
|
|||
1bdaeebf97
|
|||
ae097bfc8d
|
|||
32e75a9082
|
|||
ff36e65ed7
|
|||
42148e6292
|
|||
bdef1cac44
|
@@ -1,25 +1,43 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
BEARER_TOKEN_RES=$(
|
if [[ -z "${BEARER_TOKEN:-}" ]]; then
|
||||||
curl -L https://open.spotify.com/ \
|
printf "Atempting to scrape a bearer token...\n"
|
||||||
| 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=$(
|
BEARER_TOKEN_RES=$(
|
||||||
curl -X POST https://clienttoken.spotify.com/v1/clienttoken \
|
curl -sL https://open.spotify.com/ \
|
||||||
-H "Accept: application/json" -H "content-type: application/json" \
|
| grep 'id="session"' \
|
||||||
--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"}}}'
|
| 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
|
if [[ -z "${BEARER_TOKEN:-}" ]]; then
|
||||||
printf "\x1b[1;31m%s\x1b[0m\n" 'Token response is NOT granted' >&2
|
printf "ERR: Failed to get a bearer token, pass one with \$BEARER_TOKEN\n" >&2
|
||||||
exit 1;
|
exit 1
|
||||||
|
fi
|
||||||
|
export BEARER_TOKEN
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TOKEN=$(echo "$GUEST_TOKEN_RES" | jq -r .granted_token.token)
|
if [[ -z "${TOKEN:-}" ]]; then
|
||||||
export TOKEN
|
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
|
||||||
|
16648
spotify/playlist.json
16648
spotify/playlist.json
File diff suppressed because it is too large
Load Diff
1266
spotify/playlist.txt
Normal file
1266
spotify/playlist.txt
Normal file
File diff suppressed because it is too large
Load Diff
1266
spotify/summary-playlist.json
Normal file
1266
spotify/summary-playlist.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -6,8 +6,17 @@ MYDIR=$(dirname "$MYSELF")
|
|||||||
. "$MYDIR"/get-tokens.sh
|
. "$MYDIR"/get-tokens.sh
|
||||||
|
|
||||||
PLAYLIST_ID=${PLAYLIST_ID:-"2BoXyJeV0fhEHOy4uiByxr"}
|
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
|
iter_url=https://api.spotify.com/v1/playlists/$PLAYLIST_ID/tracks
|
||||||
while :; do
|
while :; do
|
||||||
RES=$(curl --request GET \
|
RES=$(curl --request GET \
|
||||||
@@ -18,12 +27,26 @@ while :; do
|
|||||||
iter_url=$(jq -r .next <<< "$RES")
|
iter_url=$(jq -r .next <<< "$RES")
|
||||||
echo "$RES"
|
echo "$RES"
|
||||||
|
|
||||||
i=$((i+1))
|
# _=$((i++))
|
||||||
[[ "$iter_url" == "null" ]] && break
|
[[ "$iter_url" == "null" ]] && break
|
||||||
done \
|
done \
|
||||||
| pv \
|
| pv \
|
||||||
| jq .items \
|
| jq .items \
|
||||||
| jq -s 'reduce .[] as $x ([]; . + $x)' \
|
| 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
|
||||||
|
Reference in New Issue
Block a user