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;
}
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);
}
Aggregations