From 4552ea9c9fe6ad28fb6f99e43f5cc02bdde92764 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Sat, 15 May 2021 19:42:29 +0200 Subject: [PATCH] Use the SOUNDCLOUD_API_V2_URL constant in all the SoundCloud package --- .../services/soundcloud/SoundcloudParsingHelper.java | 10 +++++----- .../extractors/SoundcloudChannelExtractor.java | 11 ++++++----- .../extractors/SoundcloudChartsExtractor.java | 6 +++--- .../extractors/SoundcloudPlaylistExtractor.java | 7 ++++--- .../extractors/SoundcloudStreamExtractor.java | 3 ++- .../extractors/SoundcloudSubscriptionExtractor.java | 6 +++--- .../extractors/SoundcloudSuggestionExtractor.java | 3 ++- .../SoundcloudSearchQueryHandlerFactory.java | 3 ++- 8 files changed, 27 insertions(+), 22 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java index 21983bfcc..c15590f32 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java @@ -16,7 +16,6 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor; -import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor; import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; import org.schabi.newpipe.extractor.utils.JsonUtils; @@ -44,7 +43,7 @@ public class SoundcloudParsingHelper { private static final String HARDCODED_CLIENT_ID = "NcIaRZItQCNQp3Vq9Plvzf7tvjmVJnF6"; // Updated on 26/04/21 private static String clientId; - public static final String SOUNDCLOUD_API_V2 = "https://api-v2.soundcloud.com/"; + public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/"; private SoundcloudParsingHelper() { } @@ -77,8 +76,9 @@ public class SoundcloudParsingHelper { final String srcUrl = element.attr("src"); if (!isNullOrEmpty(srcUrl)) { try { - return clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers) + clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers) .responseBody()); + return clientId; } catch (final RegexException ignored) { // Ignore it and proceed to try searching other script } @@ -90,7 +90,7 @@ public class SoundcloudParsingHelper { } static boolean checkIfHardcodedClientIdIsValid() throws IOException, ReCaptchaException { - final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2 + "?client_id=" + final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2_URL + "?client_id=" + HARDCODED_CLIENT_ID).responseCode(); // If the response code is 404, it means that the client_id is valid; otherwise, // it should be not valid @@ -119,7 +119,7 @@ public class SoundcloudParsingHelper { */ public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url) throws IOException, ExtractionException { - final String apiUrl = SOUNDCLOUD_API_V2 + "resolve" + "?url=" + final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve" + "?url=" + URLEncoder.encode(url, UTF_8) + "&client_id=" + clientId(); try { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java index 0cf08b324..9191e3961 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java @@ -17,6 +17,7 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; 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.EMPTY_STRING; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; @@ -24,6 +25,7 @@ import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class SoundcloudChannelExtractor extends ChannelExtractor { private String userId; private JsonObject user; + private static final String USERS_ENDPOINT = SOUNDCLOUD_API_V2_URL + "users/"; public SoundcloudChannelExtractor(final StreamingService service, final ListLinkHandler linkHandler) { @@ -35,8 +37,8 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { ExtractionException { userId = getLinkHandler().getId(); - final String apiUrl = "https://api-v2.soundcloud.com/users/" + userId + - "?client_id=" + SoundcloudParsingHelper.clientId(); + final String apiUrl = USERS_ENDPOINT + userId + "?client_id=" + + SoundcloudParsingHelper.clientId(); final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody(); try { @@ -111,9 +113,8 @@ public class SoundcloudChannelExtractor extends ChannelExtractor { final StreamInfoItemsCollector streamInfoItemsCollector = new StreamInfoItemsCollector(getServiceId()); - final String apiUrl = "https://api-v2.soundcloud.com/users/" + getId() + "/tracks" - + "?client_id=" + SoundcloudParsingHelper.clientId() + "&limit=20" - + "&linked_partitioning=1"; + final String apiUrl = USERS_ENDPOINT + getId() + "/tracks" + "?client_id=" + + SoundcloudParsingHelper.clientId() + "&limit=20" + "&linked_partitioning=1"; final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15, streamInfoItemsCollector, apiUrl); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChartsExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChartsExtractor.java index 8729c6435..5e4ca9b50 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChartsExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChartsExtractor.java @@ -15,6 +15,7 @@ import javax.annotation.Nonnull; import java.io.IOException; import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class SoundcloudChartsExtractor extends KioskExtractor { @@ -53,9 +54,8 @@ public class SoundcloudChartsExtractor extends KioskExtractor { public InfoItemsPage getInitialPage() throws IOException, ExtractionException { final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); - String apiUrl = "https://api-v2.soundcloud.com/charts" + - "?genre=soundcloud:genres:all-music" + "&client_id=" - + SoundcloudParsingHelper.clientId(); + String apiUrl = SOUNDCLOUD_API_V2_URL + "charts" + "?genre=soundcloud:genres:all-music" + + "&client_id=" + SoundcloudParsingHelper.clientId(); if (getId().equals("Top 50")) { apiUrl += "&kind=top"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java index a0d613838..2c4ac60fd 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java @@ -25,6 +25,7 @@ import java.util.List; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; public class SoundcloudPlaylistExtractor extends PlaylistExtractor { @@ -43,8 +44,8 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { ExtractionException { playlistId = getLinkHandler().getId(); - final String apiUrl = "https://api-v2.soundcloud.com/playlists/" + playlistId + - "?client_id=" + SoundcloudParsingHelper.clientId() + "&representation=compact"; + final String apiUrl = SOUNDCLOUD_API_V2_URL + "playlists/" + playlistId + "?client_id=" + + SoundcloudParsingHelper.clientId() + "&representation=compact"; final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody(); try { @@ -182,7 +183,7 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { nextIds = page.getIds().subList(STREAMS_PER_REQUESTED_PAGE, page.getIds().size()); } - final String currentPageUrl = "https://api-v2.soundcloud.com/tracks?client_id=" + final String currentPageUrl = SOUNDCLOUD_API_V2_URL + "tracks?client_id=" + SoundcloudParsingHelper.clientId() + "&ids=" + Utils.join(",", currentIds); final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java index ef68b4d8f..82bf6706b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java @@ -30,6 +30,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.*; public class SoundcloudStreamExtractor extends StreamExtractor { @@ -364,7 +365,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor { public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException { final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); - final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) + final String apiUrl = SOUNDCLOUD_API_V2_URL + "tracks/" + urlEncode(getId()) + "/related?client_id=" + urlEncode(SoundcloudParsingHelper.clientId()); SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSubscriptionExtractor.java index e700189a2..14af5ad9a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSubscriptionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSubscriptionExtractor.java @@ -13,6 +13,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps; @@ -42,9 +43,8 @@ public class SoundcloudSubscriptionExtractor extends SubscriptionExtractor { throw new InvalidSourceException(e); } - final String apiUrl = "https://api-v2.soundcloud.com/users/" + id + "/followings" - + "?client_id=" + SoundcloudParsingHelper.clientId() - + "&limit=200"; + final String apiUrl = SOUNDCLOUD_API_V2_URL + "users/" + id + "/followings" + "?client_id=" + + SoundcloudParsingHelper.clientId() + "&limit=200"; final ChannelInfoItemsCollector collector = new ChannelInfoItemsCollector(service .getServiceId()); // ± 2000 is the limit of followings on SoundCloud, so this minimum should be enough diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java index 25e62d15e..9b103f073 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java @@ -17,6 +17,7 @@ import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; public class SoundcloudSuggestionExtractor extends SuggestionExtractor { @@ -30,7 +31,7 @@ public class SoundcloudSuggestionExtractor extends SuggestionExtractor { ExtractionException { final List suggestions = new ArrayList<>(); final Downloader dl = NewPipe.getDownloader(); - final String url = "https://api-v2.soundcloud.com/search/queries" + "?q=" + final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q=" + URLEncoder.encode(query, UTF_8) + "&client_id=" + SoundcloudParsingHelper.clientId() + "&limit=10"; final String response = dl.get(url, getExtractorLocalization()).responseBody(); diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java index 79dea5257..deb3d8b6e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java @@ -11,6 +11,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.List; +import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL; import static org.schabi.newpipe.extractor.utils.Utils.UTF_8; public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory { @@ -28,7 +29,7 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto final String sortFilter) throws ParsingException { try { - String url = "https://api-v2.soundcloud.com/search"; + String url = SOUNDCLOUD_API_V2_URL + "search"; if (!contentFilter.isEmpty()) { switch (contentFilter.get(0)) {