use of org.datatransferproject.types.common.models.playlists.PlaylistContainerResource in project data-transfer-project by google.
the class SpotifyPlaylistExporter method enumeratePlaylists.
private PlaylistContainerResource enumeratePlaylists(String userId) throws IOException, SpotifyWebApiException {
List<MusicPlaylist> results = new ArrayList<>();
int offset = 0;
Paging<PlaylistSimplified> playlists;
do {
int finalOffset = offset;
monitor.debug(() -> format("Fetching playlists with offset %s", finalOffset));
playlists = spotifyApi.getListOfUsersPlaylists(userId).offset(offset).build().execute();
for (PlaylistSimplified playlist : playlists.getItems()) {
monitor.debug(() -> format("Got playlist %s: %s (id: %s)", playlist.getId(), playlist.getName(), playlist.getHref()));
results.add(new MusicPlaylist(playlist.getHref(), playlist.getName(), fetchPlaylist(playlist.getId())));
}
offset += playlists.getItems().length;
} while (!Strings.isNullOrEmpty(playlists.getNext()) && playlists.getItems().length > 0);
return new PlaylistContainerResource(results);
}
Aggregations