Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotify GetPlaylistUri only works properly up to 50 user playlists #749

Open
basti4557 opened this issue Nov 28, 2023 · 1 comment
Open

Comments

@basti4557
Copy link

basti4557 commented Nov 28, 2023

When using spotify with many playlists (51+) a problem with GetPlaylistUri can occur. The API call in getPlaylistUri() is limited to 50 entries with offset 0.

See: https://developer.spotify.com/documentation/web-api/reference/get-list-users-playlists

The Solution would be using the "total" key in the response to calculate a type of "pagination" to cycle through all playlists.
For example:

Total 150 should be 3 pages, so fetch
getClientPlaylists(50,0), getClientPlaylists(50,50) and getClientPlaylists(50,100)

var playlists = webApi?.playlists?.getClientPlaylists(50,0)

suspend fun getPlaylistUri(playlistName: String): SpotifyUri? = executeApiCall("Failed to find playlist with name $playlistName") {
		var playlists = webApi?.playlists?.getClientPlaylists(50,0)
		while (playlists != null) {
			val matchingPlaylist = playlists.items.find { it.name == playlistName }
			if (matchingPlaylist != null) {
				return@executeApiCall matchingPlaylist.uri
			}
			playlists = playlists.getNext()
		}

		return@executeApiCall null
	}
@hufman
Copy link
Collaborator

hufman commented Nov 29, 2023

Good catch!
SpotifyWebApi.getPlaylistUri is only used by the SpotifyAppController to manage the temporary cloned playlists of the buggy Liked Songs and Artist Radio playlists. If a user has add 50 playlists since the last time AAIdrive has updated this cloned playlist, I expect it will create a duplicate at the top of the list, or perhaps throw an error and not enable this workaround for skipping in these playlists. I personally dislike this workaround and wish it wasn't even needed, so I haven't tried polishing this particular facet :)

Definitely something to fix at some point! You can check the example for how AAIdrive iterates through the contents of a playlist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants