Create a gist now

Instantly share code, notes, and snippets.

Own your list of favourite tracks on Spotify
#!/bin/bash
#
# you need
# https://github.com/jehiah/json2csv and
# https://stedolan.github.io/jq/
# to roll like this
#
# get your token at https://developer.spotify.com/web-api/console/get-current-user-saved-tracks/
#
token="..."
uri="https://api.spotify.com/v1/me/tracks?offset=0&limit=20"
while [ "$next" != "null" ]; do
buffer=$(curl -s -X GET "$uri" -H "Accept: application/json" -H "Authorization: Bearer $token")
echo "$buffer" | jq -c '.items[] | {album_id: .track.album.id, album_name: .track.album.name, artist: .track.artists[0].name, title: .track.name, uri: .track.uri}' | \
json2csv -k album_id,album_name,artist,title,uri
uri=$(echo "$buffer" | jq -c '.next' | tr -d '"')
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment