Skip to content

Commit 4552ea9

Browse files
committed
Use the SOUNDCLOUD_API_V2_URL constant in all the SoundCloud package
1 parent 86308d0 commit 4552ea9

8 files changed

Lines changed: 27 additions & 22 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1717
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
1818
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelInfoItemExtractor;
19-
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor;
2019
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamInfoItemExtractor;
2120
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2221
import org.schabi.newpipe.extractor.utils.JsonUtils;
@@ -44,7 +43,7 @@ public class SoundcloudParsingHelper {
4443
private static final String HARDCODED_CLIENT_ID =
4544
"NcIaRZItQCNQp3Vq9Plvzf7tvjmVJnF6"; // Updated on 26/04/21
4645
private static String clientId;
47-
public static final String SOUNDCLOUD_API_V2 = "https://api-v2.soundcloud.com/";
46+
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
4847

4948
private SoundcloudParsingHelper() {
5049
}
@@ -77,8 +76,9 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
7776
final String srcUrl = element.attr("src");
7877
if (!isNullOrEmpty(srcUrl)) {
7978
try {
80-
return clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers)
79+
clientId = Parser.matchGroup1(clientIdPattern, dl.get(srcUrl, headers)
8180
.responseBody());
81+
return clientId;
8282
} catch (final RegexException ignored) {
8383
// Ignore it and proceed to try searching other script
8484
}
@@ -90,7 +90,7 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
9090
}
9191

9292
static boolean checkIfHardcodedClientIdIsValid() throws IOException, ReCaptchaException {
93-
final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2 + "?client_id="
93+
final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2_URL + "?client_id="
9494
+ HARDCODED_CLIENT_ID).responseCode();
9595
// If the response code is 404, it means that the client_id is valid; otherwise,
9696
// it should be not valid
@@ -119,7 +119,7 @@ public static OffsetDateTime parseDateFrom(final String textualUploadDate)
119119
*/
120120
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
121121
throws IOException, ExtractionException {
122-
final String apiUrl = SOUNDCLOUD_API_V2 + "resolve" + "?url="
122+
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve" + "?url="
123123
+ URLEncoder.encode(url, UTF_8) + "&client_id=" + clientId();
124124

125125
try {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import javax.annotation.Nonnull;
1818
import java.io.IOException;
1919

20+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
2021
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
2122
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2223

2324
@SuppressWarnings("WeakerAccess")
2425
public class SoundcloudChannelExtractor extends ChannelExtractor {
2526
private String userId;
2627
private JsonObject user;
28+
private static final String USERS_ENDPOINT = SOUNDCLOUD_API_V2_URL + "users/";
2729

2830
public SoundcloudChannelExtractor(final StreamingService service,
2931
final ListLinkHandler linkHandler) {
@@ -35,8 +37,8 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
3537
ExtractionException {
3638

3739
userId = getLinkHandler().getId();
38-
final String apiUrl = "https://api-v2.soundcloud.com/users/" + userId +
39-
"?client_id=" + SoundcloudParsingHelper.clientId();
40+
final String apiUrl = USERS_ENDPOINT + userId + "?client_id="
41+
+ SoundcloudParsingHelper.clientId();
4042

4143
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
4244
try {
@@ -111,9 +113,8 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException
111113
final StreamInfoItemsCollector streamInfoItemsCollector =
112114
new StreamInfoItemsCollector(getServiceId());
113115

114-
final String apiUrl = "https://api-v2.soundcloud.com/users/" + getId() + "/tracks"
115-
+ "?client_id=" + SoundcloudParsingHelper.clientId() + "&limit=20"
116-
+ "&linked_partitioning=1";
116+
final String apiUrl = USERS_ENDPOINT + getId() + "/tracks" + "?client_id="
117+
+ SoundcloudParsingHelper.clientId() + "&limit=20" + "&linked_partitioning=1";
117118

118119
final String nextPageUrl = SoundcloudParsingHelper.getStreamsFromApiMinItems(15,
119120
streamInfoItemsCollector, apiUrl);

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChartsExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.IOException;
1616

1717
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
18+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
1819
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
1920

2021
public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
@@ -53,9 +54,8 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException
5354
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
5455
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
5556

56-
String apiUrl = "https://api-v2.soundcloud.com/charts" +
57-
"?genre=soundcloud:genres:all-music" + "&client_id="
58-
+ SoundcloudParsingHelper.clientId();
57+
String apiUrl = SOUNDCLOUD_API_V2_URL + "charts" + "?genre=soundcloud:genres:all-music"
58+
+ "&client_id=" + SoundcloudParsingHelper.clientId();
5959

6060
if (getId().equals("Top 50")) {
6161
apiUrl += "&kind=top";

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.annotation.Nonnull;
2626
import javax.annotation.Nullable;
2727

28+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
2829
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2930

3031
public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
@@ -43,8 +44,8 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
4344
ExtractionException {
4445

4546
playlistId = getLinkHandler().getId();
46-
final String apiUrl = "https://api-v2.soundcloud.com/playlists/" + playlistId +
47-
"?client_id=" + SoundcloudParsingHelper.clientId() + "&representation=compact";
47+
final String apiUrl = SOUNDCLOUD_API_V2_URL + "playlists/" + playlistId + "?client_id="
48+
+ SoundcloudParsingHelper.clientId() + "&representation=compact";
4849

4950
final String response = downloader.get(apiUrl, getExtractorLocalization()).responseBody();
5051
try {
@@ -182,7 +183,7 @@ public InfoItemsPage<StreamInfoItem> getPage(final Page page) throws IOException
182183
nextIds = page.getIds().subList(STREAMS_PER_REQUESTED_PAGE, page.getIds().size());
183184
}
184185

185-
final String currentPageUrl = "https://api-v2.soundcloud.com/tracks?client_id="
186+
final String currentPageUrl = SOUNDCLOUD_API_V2_URL + "tracks?client_id="
186187
+ SoundcloudParsingHelper.clientId() + "&ids=" + Utils.join(",", currentIds);
187188

188189
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.List;
3131
import java.util.Locale;
3232

33+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
3334
import static org.schabi.newpipe.extractor.utils.Utils.*;
3435

3536
public class SoundcloudStreamExtractor extends StreamExtractor {
@@ -364,7 +365,7 @@ public StreamType getStreamType() {
364365
public StreamInfoItemsCollector getRelatedItems() throws IOException, ExtractionException {
365366
final StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
366367

367-
final String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId())
368+
final String apiUrl = SOUNDCLOUD_API_V2_URL + "tracks/" + urlEncode(getId())
368369
+ "/related?client_id=" + urlEncode(SoundcloudParsingHelper.clientId());
369370

370371
SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl);

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSubscriptionExtractor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Collections;
1414
import java.util.List;
1515

16+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
1617
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
1718
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
1819

@@ -42,9 +43,8 @@ public List<SubscriptionItem> fromChannelUrl(final String channelUrl) throws IOE
4243
throw new InvalidSourceException(e);
4344
}
4445

45-
final String apiUrl = "https://api-v2.soundcloud.com/users/" + id + "/followings"
46-
+ "?client_id=" + SoundcloudParsingHelper.clientId()
47-
+ "&limit=200";
46+
final String apiUrl = SOUNDCLOUD_API_V2_URL + "users/" + id + "/followings" + "?client_id="
47+
+ SoundcloudParsingHelper.clientId() + "&limit=200";
4848
final ChannelInfoItemsCollector collector = new ChannelInfoItemsCollector(service
4949
.getServiceId());
5050
// ± 2000 is the limit of followings on SoundCloud, so this minimum should be enough

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudSuggestionExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.ArrayList;
1818
import java.util.List;
1919

20+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
2021
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
2122

2223
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
@@ -30,7 +31,7 @@ public List<String> suggestionList(final String query) throws IOException,
3031
ExtractionException {
3132
final List<String> suggestions = new ArrayList<>();
3233
final Downloader dl = NewPipe.getDownloader();
33-
final String url = "https://api-v2.soundcloud.com/search/queries" + "?q="
34+
final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q="
3435
+ URLEncoder.encode(query, UTF_8) + "&client_id="
3536
+ SoundcloudParsingHelper.clientId() + "&limit=10";
3637
final String response = dl.get(url, getExtractorLocalization()).responseBody();

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudSearchQueryHandlerFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.URLEncoder;
1212
import java.util.List;
1313

14+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
1415
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
1516

1617
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
@@ -28,7 +29,7 @@ public String getUrl(final String id,
2829
final String sortFilter)
2930
throws ParsingException {
3031
try {
31-
String url = "https://api-v2.soundcloud.com/search";
32+
String url = SOUNDCLOUD_API_V2_URL + "search";
3233

3334
if (!contentFilter.isEmpty()) {
3435
switch (contentFilter.get(0)) {

0 commit comments

Comments
 (0)