From cf2486f549eb22c1aa1ce211ca082fab8d5001f9 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 24 Jan 2025 22:13:14 +0100 Subject: [PATCH] feat: better scripts & less fingerprinting info --- spotify/get-tokens.sh | 2 +- spotify/update-playlist.sh | 32 ++++++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/spotify/get-tokens.sh b/spotify/get-tokens.sh index ecf4f14..175c9a7 100755 --- a/spotify/get-tokens.sh +++ b/spotify/get-tokens.sh @@ -13,7 +13,7 @@ export BEARER_TOKEN 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.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"}}}' + --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 diff --git a/spotify/update-playlist.sh b/spotify/update-playlist.sh index a0e6478..9f0387a 100755 --- a/spotify/update-playlist.sh +++ b/spotify/update-playlist.sh @@ -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,20 +27,23 @@ 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\n" "$(jq length playlist.json)" +ARR=" "$'\x1b'"[32m=>"$'\x1b'"[0m" -jq -r '.[].track | ( .name + " - " + (.album.artists | map(.name) | join(", ")) )' playlist.json \ - > playlist.txt -printf "and dumped it as text on %s\n" playlist.txt +printf "$ARR downloaded \x1b[33m%s\x1b[0m songs metadata at \x1b[35m%s\x1b[0m\n" \ + "$(jq length "$PLAYLIST_JSON")" "$PLAYLIST_JSON" -jq -c '.[].track | ( [.id, .name, .album.name, (.album.artists | map(.name))] )' playlist.json \ - > summary-playlist.json -printf "AND dumped summary metadata on %s\n" summary-playlist.txt +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"