-1

So I'm struggling to decode Spotify's Web Authentication set up. What I'm looking to do is create a bash script to add the currently playing song to a predetermined playlist. The aim is to have it so I can push a keyboard shortcut and save it.

So far I have Keyboard Maestro accepting a Hot Key and running some Applescript to pull the TrackID from Spotify. Is it possible to have a Bash script (which Keyboard Maestro can run) do a POST request.

I can run unauthenticated API searches but it's authentication where I'm hitting issues.

user3733863
  • 81
  • 1
  • 5

2 Answers2

1

I found this in Spotify's API

POST https://api.spotify.com/v1/users/{user_id}/playlists/{playlist_id}/tracks

https://developer.spotify.com/web-api/add-tracks-to-playlist/

Example

curl -i -X POST "https://api.spotify.com/v1/users/wizzler/playlists/7oi0w0SLbJ4YyjrOxhZbUv/tracks?uris=spotify%3Atrack%3A4iV5W9uYEdYUVa79Axb7Rh,spotify%3Atrack%3A1301WleyT98MSxVHPZCA6M" -H "Authorization: Bearer {your access token}" -H "Accept: application/json"

HTTP/1.1 201 Created
{ "snapshot_id" : "JbtmHBDBAYu3/bt8BOXKjzKx3i0b6LCa/wVjyl6qQ2Yf6nFXkbmzuEa+ZI/U1yF+" }
nicandris
  • 327
  • 3
  • 14
  • Yeah, the issue is generating the access token without a web frontend. The [Client Credentials](https://developer.spotify.com/web-api/authorization-guide/#client-credentials-flow) flow grants one but not with authorisation. – user3733863 Apr 17 '16 at 17:01
  • You can create an authorization code by using: GET https://accounts.spotify.com/authorize – nicandris Apr 17 '16 at 17:06
1

I know that the linux Spotify Client has dbus functionality - and it is entirely possible to manage playlist(s) with DBUS and the Spotify Client.
I have linked a Spotify Forum page, that is by no means an absolute authority on the matter, but it does make it very clear the API is DBUS compatible and that Playlists are one of the many things you can manipulate.

I've attached both the WebAPI and the LibSpotify API links below as well.. As choice is king!!

Add DBus methods for Spotify playlist control
Web API User Guide
Libspotify SDK

Iván Rodríguez Torres
  • 4,293
  • 3
  • 31
  • 47
Matty
  • 111
  • 8