Spotify.ahk icon indicating copy to clipboard operation
Spotify.ahk copied to clipboard

Add GetPlaylistTracks and AddTracksPage methods to retrieve playlists…

Open JnLlnd opened this issue 3 years ago • 3 comments

… with more than 100 tracks

JnLlnd avatar Aug 20 '22 14:08 JnLlnd

I added these 2 methods to allow retrieving playlist having more than 100 tracks.

Looking at the JSON returned by the API, I found that the endpoint to get the playlist BASE_URL . "playlists/" . playlist_id returns info about the playlist and includes the 100 first tracks in the tracks.items array. This endpoint does not support the offset parameter.

To get the remaining tracks, I used the BASE_URL . "playlists/"' . playlist_id . "/tracks?offset=100". This endpoint supports the limit and offset parameters. It returns the tracks in the items array. The new method is looping this API call incrementing offset by 100 until the JSON return an empty items array.

JnLlnd avatar Aug 20 '22 15:08 JnLlnd

Looks like this one was fun to debug 🙂, I'm a "thousands of liked songs, zero playlists" kind of person so I never bumped into this lol.

Unfortunately I'm stuck using a hotspot for my connection until Sunday and can barely even get the diff to load properly, so I can only really give a big block of text as feedback for now (the API times out when I try to test, and I'll be shocked if this comment even goes through).

My only nitpick is that the name .GetPlaylistTracks is a bit misleading, I read it as "get array of all tracks in playlist" and not "get playlist object containing all tracks". I think it might be better to move the logic into a method of class Playlist instead, so the usage looks more like MySpotify.Playlists.GetPlaylist("spotify:whatever").GetAllTracks(). Plus, the distinction between a "full" playlist object (from .GetPlaylistTracks) and a "partial" one (from anywhere else) could be hard to track, so I think it would be better to leave all playlists incomplete, and have people jump through a hoop or two to get the full track list.

I like the CSV example a lot, I've found myself reinventing that wheel many times but never considered turning it into an example, thanks for including it. It looks like you also included a renamed/reworded copy of the example hotkeys file. I'm fine with updating the existing version but would rather not duplicate it.

CloakerSmoker avatar Aug 23 '22 19:08 CloakerSmoker

I'll be shocked if this comment even goes through

It did :-)

I think it might be better to move the logic into a method of class Playlist instead, so the usage looks more like MySpotify.Playlists.GetPlaylist("spotify:whatever").GetAllTracks().

Done. See new pull request in a minute.

Plus, the distinction between a "full" playlist object (from .GetPlaylistTracks) and a "partial" one (from anywhere else) could be hard to track, so I think it would be better to leave all playlists incomplete, and have people jump through a hoop or two to get the full track list.

Not sure what you mean exactly. Please, see if the new pull request is OK to you.

I like the CSV example a lot, I've found myself reinventing that wheel many times but never considered turning it into an example, thanks for including it.

Thanks. This ObjCSV library is one of the first things I coded after learning how to play with objects, close to 10 years ago.

It looks like you also included a renamed/reworded copy of the example hotkeys file. I'm fine with updating the existing version but would rather not duplicate it.

Done in the new pull request.

JnLlnd avatar Aug 23 '22 23:08 JnLlnd

Thanks :-)

JnLlnd avatar Nov 03 '22 18:11 JnLlnd