BenediktAlkin / SongTaggerForSpotify

Song tagging for Spotify
MIT License
83 stars 4 forks source link

HTTP API #4

Closed vokinpirks closed 2 years ago

vokinpirks commented 2 years ago

Hello! Thank you for this. This is exactly what I have been planning to impement for myself for ages but couldn't due to the lack of spare time (and tbh I was just too lazy at times).

Is there HTTP API available for tagging? Why am I asking? Well, there is the Spotify Destop extension solution called Spicetify. I made some experiments with it and found out that it's pretty simple to modify the Spotify context menu to add some custom functionality to it written in JS. The idea is to incorporate tagging directly into Spotify. One can just right click on a track/album/artist/playlist and apply a tag without the need to go somewhere else. I find this very convinient. Here is the demonstration of rating and tagging respectively: https://photos.app.goo.gl/rn5g3JXXq7jqAL2J8
https://photos.app.goo.gl/aT1izaivRybDWJk56 (I consider ratings to be just a special case of tags) I just don't have a back-end for tagging for now. If your service had HTTP API I could use it as back-end. Of course, I would share the Spicetify extension I made too on Github so everyone could use it. What do you think of my idea?

BenediktAlkin commented 2 years ago

Hi!

That is an awesome idea and would also greatly improve the experience for users without Spotify premium (they can't play a song by double clicking it in the Song Tagger because the Spotify API doesn't allow that, so they'd have to play the song in the Spotify client and then switch back to the Song Tagger to tag it).

Right now no HTTP API is available, but it should be easy to implement it. I'll probably implement it in the coming days. However, for now it probably will be without "tag groups" (you can still group them in the Spicetify extension). I do plan to implement tag groups at some point, but it has a low priority.

vokinpirks commented 2 years ago

That's some great news, I'm very excited! I really don't even need tag groups. The tags hierarchy is configured on the client side.

I need these API endpoints:

Add Tag Delete Tag Check Tag
tracks POST tags/{tag}/track?id={}&id={}&...
add tag to all specifed tracks
DELETE tags/{tag}/track?id={}&id={}&...
delete tag from all speciifed tracks
GET tags/{tag}/track?id={}&id={}&...
check if tag is applied to all specified tracks. returns: NONE/SOME/ALL
albums POST tags/{tag}/album?id={}
add tag to all tracks of specified album
DELETE tags/{tag}/album?id={}
delete tag from all tracks of specified album
GET tags/{tag}/album?id={}
check if tag is applied to all tracks of specified album. returns: NONE/SOME/ALL
playlists POST tags/{tag}/playlist?id={}
add tag to all tracks of specified playlist
DELETE tags/{tag}/playlist?id={}
delete tag from all tracks of specified playlist
GET tags/{tag}/playlist?id={}
check if tag is applied to all tracks of specified playlist. returns: NONE/SOME/ALL

In case a user hasn't configured the extension, the latter would fallback to 'flat' structure showing just all the tags that were created in Tagger. So I also need an API method to fetch all tags: GET tags/ returns: [tag1, tag2, ..]

Let me know what you think.

BenediktAlkin commented 2 years ago

I just released the v1.0.2 version, it contains a BackendAPI.exe file that implements the HTTP API (the app automatically updates if you have not disabled that option). A documentation for it can be found here

All the API endpoints you need are implemented. In addition, the user needs to login before using the API (this login is seperate from the one the SpotifySongTagger.exe uses). When you open the BackendAPI.exe it will automatically prompt a login if the user is not logged in yet. The connection to spotify from the API can also be controlled with the connection endpoint.

In addition to GET tags/ I provided a GET taggroups/ for forward compatibility. Right now it just returns all tags in a default group, but once taggroups are implemented, this will be updated to properly return the taggroups.

vokinpirks commented 2 years ago

@BenediktAlkin thank you very much. I have coronavirus now, will try out once I get well.

vokinpirks commented 2 years ago

Unfortunately, I have a problem with the API. The library Spicetify provides for HTTP requests can't handle content types other than JSON, so I got an error whenever the Tagger backend issues text/plain response, in particular connection/userid and all the endpoints for checking tags (get tags/{tag}/tracks|playlist|album?id=...). Would you please change the API endpoints to produce JSON? Something like these would be good get connection/userid returns {"userId": "{value}"} get tags/{tag}/tracks?id={id} returns {"result": "NONE|SOME|ALL"}

BenediktAlkin commented 2 years ago

I added json endpoints to the api. You can call endpoints that return something with prefixed json/ to get the result wrapped into json format. GET connection/userid returns exampleuserid GET json/connection/userid returns {"result":"exampleuserid"}

vokinpirks commented 2 years ago

I've finished the extension. Been testing it. The API works fine. So I'm closing this.