Spotify.ahk
Spotify.ahk copied to clipboard
Add GetPlaylistTracks and AddTracksPage methods to retrieve playlists…
… with more than 100 tracks
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.
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.
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.
Thanks :-)