2022-10-24 00:11:00 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.InfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
|
|
|
|
import org.schabi.newpipe.extractor.Page;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelTabExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2022-11-04 23:47:44 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ChannelTabs;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2022-10-24 00:11:00 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
|
|
|
|
|
|
public class SoundcloudChannelTabExtractor extends ChannelTabExtractor {
|
|
|
|
private final String userId;
|
|
|
|
private static final String USERS_ENDPOINT = SOUNDCLOUD_API_V2_URL + "users/";
|
|
|
|
|
|
|
|
public SoundcloudChannelTabExtractor(final StreamingService service,
|
2022-11-04 23:47:44 +01:00
|
|
|
final ListLinkHandler linkHandler) {
|
2022-10-24 00:11:00 +02:00
|
|
|
super(service, linkHandler);
|
|
|
|
userId = getLinkHandler().getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getEndpoint() {
|
|
|
|
switch (getTab()) {
|
2023-04-13 11:03:37 +02:00
|
|
|
case ChannelTabs.TRACKS:
|
|
|
|
return "/tracks";
|
2022-11-04 23:47:44 +01:00
|
|
|
case ChannelTabs.PLAYLISTS:
|
2022-10-24 00:11:00 +02:00
|
|
|
return "/playlists_without_albums";
|
2022-11-04 23:47:44 +01:00
|
|
|
case ChannelTabs.ALBUMS:
|
2022-10-24 00:11:00 +02:00
|
|
|
return "/albums";
|
|
|
|
}
|
2022-11-04 23:47:44 +01:00
|
|
|
throw new IllegalArgumentException("unsupported tab: " + getTab());
|
2022-10-25 21:13:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-24 00:11:00 +02:00
|
|
|
@Override
|
2023-04-13 11:03:37 +02:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader) {
|
2022-10-24 00:11:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getId() {
|
|
|
|
return userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
|
|
|
|
return getPage(new Page(USERS_ENDPOINT + userId + getEndpoint() + "?client_id="
|
|
|
|
+ SoundcloudParsingHelper.clientId() + "&limit=20" + "&linked_partitioning=1"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<InfoItem> getPage(final Page page)
|
|
|
|
throws IOException, ExtractionException {
|
|
|
|
if (page == null || isNullOrEmpty(page.getUrl())) {
|
|
|
|
throw new IllegalArgumentException("Page doesn't contain an URL");
|
|
|
|
}
|
|
|
|
|
|
|
|
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
|
|
|
|
final String nextPageUrl = SoundcloudParsingHelper.getInfoItemsFromApi(collector,
|
|
|
|
page.getUrl());
|
|
|
|
|
|
|
|
return new InfoItemsPage<>(collector, new Page(nextPageUrl));
|
|
|
|
}
|
|
|
|
}
|