Search in sources :

Example 1 with MusicPlaylist

use of org.datatransferproject.types.common.models.playlists.MusicPlaylist in project data-transfer-project by google.

the class SpotifyPlaylistImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, TokensAndUrlAuthData authData, PlaylistContainerResource data) throws Exception {
    spotifyApi.setAccessToken(authData.getAccessToken());
    spotifyApi.setRefreshToken(authData.getRefreshToken());
    User user = spotifyApi.getCurrentUsersProfile().build().execute();
    for (MusicPlaylist playlist : data.getLists()) {
        createPlaylist(idempotentExecutor, playlist, user.getId());
    }
    return ImportResult.OK;
}
Also used : User(com.wrapper.spotify.model_objects.specification.User) MusicPlaylist(org.datatransferproject.types.common.models.playlists.MusicPlaylist)

Example 2 with MusicPlaylist

use of org.datatransferproject.types.common.models.playlists.MusicPlaylist 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

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