catharsis / spotifile

FUSE file system for Spotify
BSD 3-Clause "New" or "Revised" License
144 stars 7 forks source link

Add user's songs, artists, album as separate directories #45

Open gsora opened 8 years ago

gsora commented 8 years ago

Right now Spotify groups user's music under the "Your Music" tab.

A similar implementation could be useful, since not everyone keeps all of its preferred music in playlists.

catharsis commented 8 years ago

I'm definitely open to this type of improvement, given that we can figure out a nice way of representing it structurally. Are the artists/albums/songs for a user the same as those saved as part of playlists or something else? What I'm getting at is, that if it's a completely separate concept from playlists, it will probably not be possible since it is not exposed through the libspotify API.

gsora commented 8 years ago

"Your Music" tab is where a song goes if for example, while listening to the Spotify Radio a user press the "plus" button.

Every song added to "Your Music" can be added to a playlist, so there's definitely a relationship between a playlist and this view.

gsora commented 8 years ago

Doh, I'm afraid this function can't be implemented.

After a quick search, this blog post came up.

Basically, libspotify doesn't let the implementer access this kind of information...

That's a shame.

catharsis commented 8 years ago

Yeah, I was afraid of that.

However! https://developer.spotify.com/web-api/endpoint-reference/ does expose the information, and I don't have any problem per se with using multiple API's to provide this feature, if necessary.

I probably won't be implementing this myself in the foreseeable future, but I'd gladly discuss a patch to include it, were one proposed.

gsora commented 8 years ago

Oh, it seems!

In particular, this endpoint could be useful for the implementation:

GET https://api.spotify.com/v1/me/tracks

As the documentation says, this returns some JSON containing a list of the saved tracks, maximum 50 per request.

It's possible to add an offset per request, and the response itself tells us if there's any need to make another request of this type.

The items object contains various information, including the track uri, in this format:

spotify:track:XXXXXXXXXXXXXXXXXXXX

The only caveats might be how to get a OAuth token. Do libspotify uses the same type of authorization?

catharsis commented 8 years ago

Right, so we could just materialize the various resources based on the URI, that should work.

I've never implemented OAuth myself, so I'm not sure how to do it, I'd need to look into that (might be a good opportunity for me to finally read up on OAuth as well ;)). libspotify simply lets you specify the username & password (and an API key) and takes care of the rest for you - notifying you of success/failure via callbacks. I'm not sure how it works beyond that.

gsora commented 8 years ago

Spotify does not offer any "secret code" OAuth login, but their implementation of the implicit grant flow could be successfully implemented without any server-side code.