2020-04-10 10:51:05 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
2017-08-20 10:03:41 +02:00
|
|
|
|
2020-04-15 14:09:46 +02:00
|
|
|
import org.schabi.newpipe.extractor.Page;
|
2017-08-20 10:03:41 +02:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
2020-02-08 23:58:46 +01:00
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
2017-08-20 10:03:41 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2021-02-11 23:24:33 +01:00
|
|
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
2020-04-10 10:51:05 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
2018-03-01 01:02:43 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
2018-02-24 22:20:50 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
2017-08-20 10:03:41 +02:00
|
|
|
|
2020-05-11 15:25:18 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2021-02-11 23:24:33 +01:00
|
|
|
import java.io.IOException;
|
2020-05-11 15:25:18 +02:00
|
|
|
|
2020-03-29 11:13:39 +02:00
|
|
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
2021-05-15 19:42:29 +02:00
|
|
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
2020-05-11 11:40:24 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
2020-03-29 11:13:39 +02:00
|
|
|
|
2019-01-28 12:18:16 +01:00
|
|
|
public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
|
2021-05-15 17:51:43 +02:00
|
|
|
public SoundcloudChartsExtractor(final StreamingService service,
|
|
|
|
final ListLinkHandler linkHandler,
|
|
|
|
final String kioskId) {
|
2019-04-28 22:03:16 +02:00
|
|
|
super(service, linkHandler, kioskId);
|
2017-08-20 10:03:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader) {
|
2017-08-20 10:03:41 +02:00
|
|
|
}
|
|
|
|
|
2017-11-25 01:10:04 +01:00
|
|
|
@Nonnull
|
2017-08-20 10:03:41 +02:00
|
|
|
@Override
|
2018-02-24 22:20:50 +01:00
|
|
|
public String getName() {
|
2018-04-01 20:27:44 +02:00
|
|
|
return getId();
|
2017-08-20 10:03:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-05-15 17:51:43 +02:00
|
|
|
public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException,
|
|
|
|
ExtractionException {
|
2020-05-11 15:25:18 +02:00
|
|
|
if (page == null || isNullOrEmpty(page.getUrl())) {
|
|
|
|
throw new IllegalArgumentException("Page doesn't contain an URL");
|
|
|
|
}
|
|
|
|
|
2020-06-13 20:25:38 +02:00
|
|
|
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
2021-05-15 17:51:43 +02:00
|
|
|
final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector,
|
|
|
|
page.getUrl(), true);
|
2018-02-26 15:55:27 +01:00
|
|
|
|
2020-04-15 14:09:46 +02:00
|
|
|
return new InfoItemsPage<>(collector, new Page(nextPageUrl));
|
2020-04-10 10:25:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
2020-06-13 20:25:38 +02:00
|
|
|
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
2017-08-20 10:03:41 +02:00
|
|
|
|
2021-05-15 19:42:29 +02:00
|
|
|
String apiUrl = SOUNDCLOUD_API_V2_URL + "charts" + "?genre=soundcloud:genres:all-music"
|
|
|
|
+ "&client_id=" + SoundcloudParsingHelper.clientId();
|
2017-08-20 10:03:41 +02:00
|
|
|
|
2017-09-25 12:43:40 +02:00
|
|
|
if (getId().equals("Top 50")) {
|
2017-08-20 10:03:41 +02:00
|
|
|
apiUrl += "&kind=top";
|
|
|
|
} else {
|
2017-12-24 23:15:40 +01:00
|
|
|
apiUrl += "&kind=trending";
|
2017-08-20 10:03:41 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 23:24:33 +01:00
|
|
|
final ContentCountry contentCountry = SoundCloud.getContentCountry();
|
|
|
|
String apiUrlWithRegion = null;
|
|
|
|
if (getService().getSupportedCountries().contains(contentCountry)) {
|
2021-05-15 17:51:43 +02:00
|
|
|
apiUrlWithRegion = apiUrl + "®ion=soundcloud:regions:"
|
|
|
|
+ contentCountry.getCountryCode();
|
2021-02-11 23:24:33 +01:00
|
|
|
}
|
2017-08-22 14:47:51 +02:00
|
|
|
|
2021-02-11 23:24:33 +01:00
|
|
|
String nextPageUrl;
|
|
|
|
try {
|
2021-05-15 17:51:43 +02:00
|
|
|
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector,
|
|
|
|
apiUrlWithRegion == null ? apiUrl : apiUrlWithRegion, true);
|
|
|
|
} catch (final IOException e) {
|
|
|
|
// Request to other region may be geo-restricted.
|
|
|
|
// See https://github.com/TeamNewPipe/NewPipeExtractor/issues/537.
|
|
|
|
// We retry without the specified region.
|
2021-02-11 23:24:33 +01:00
|
|
|
nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl, true);
|
|
|
|
}
|
2018-02-26 15:55:27 +01:00
|
|
|
|
2020-04-15 14:09:46 +02:00
|
|
|
return new InfoItemsPage<>(collector, new Page(nextPageUrl));
|
2017-08-20 10:03:41 +02:00
|
|
|
}
|
|
|
|
}
|