Skip to content

Instantly share code, notes, and snippets.

@soobrosa
Last active February 15, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soobrosa/a6119b2ee35555c296f3 to your computer and use it in GitHub Desktop.
Save soobrosa/a6119b2ee35555c296f3 to your computer and use it in GitHub Desktop.
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