Search in sources :

Example 1 with PlaylistContainerResource

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);
}
Also used : PlaylistContainerResource(org.datatransferproject.types.common.models.playlists.PlaylistContainerResource) ArrayList(java.util.ArrayList) MusicPlaylist(org.datatransferproject.types.common.models.playlists.MusicPlaylist) PlaylistSimplified(com.wrapper.spotify.model_objects.specification.PlaylistSimplified)

Aggregations

PlaylistSimplified (com.wrapper.spotify.model_objects.specification.PlaylistSimplified)1 ArrayList (java.util.ArrayList)1 MusicPlaylist (org.datatransferproject.types.common.models.playlists.MusicPlaylist)1 PlaylistContainerResource (org.datatransferproject.types.common.models.playlists.PlaylistContainerResource)1