|
6 | 6 | import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
7 | 7 | import org.schabi.newpipe.extractor.kiosk.KioskExtractor; |
8 | 8 | import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; |
| 9 | +import org.schabi.newpipe.extractor.localization.ContentCountry; |
9 | 10 | import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper; |
10 | 11 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
11 | 12 | import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; |
12 | 13 |
|
13 | | -import java.io.IOException; |
14 | | - |
15 | 14 | import javax.annotation.Nonnull; |
| 15 | +import java.io.IOException; |
16 | 16 |
|
17 | 17 | import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; |
18 | 18 | import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; |
@@ -61,10 +61,20 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, Extrac |
61 | 61 | apiUrl += "&kind=trending"; |
62 | 62 | } |
63 | 63 |
|
64 | | - final String contentCountry = SoundCloud.getContentCountry().getCountryCode(); |
65 | | - apiUrl += "®ion=soundcloud:regions:" + contentCountry; |
| 64 | + final ContentCountry contentCountry = SoundCloud.getContentCountry(); |
| 65 | + String apiUrlWithRegion = null; |
| 66 | + if (getService().getSupportedCountries().contains(contentCountry)) { |
| 67 | + apiUrlWithRegion = apiUrl + "®ion=soundcloud:regions:" + contentCountry.getCountryCode(); |
| 68 | + } |
66 | 69 |
|
67 | | - final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl, true); |
| 70 | + String nextPageUrl; |
| 71 | + try { |
| 72 | + nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrlWithRegion == null ? apiUrl : apiUrlWithRegion, true); |
| 73 | + } catch (IOException e) { |
| 74 | + // Request to other region may be geo-restricted. See https://github.com/TeamNewPipe/NewPipeExtractor/issues/537 |
| 75 | + // we retry without the specified region. |
| 76 | + nextPageUrl = SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl, true); |
| 77 | + } |
68 | 78 |
|
69 | 79 | return new InfoItemsPage<>(collector, new Page(nextPageUrl)); |
70 | 80 | } |
|
0 commit comments