Skip to content

Commit ba56be8

Browse files
committed
Removed hardcoded soundcloud id
It never works (long enough) so let's simply remove it...
1 parent e7aee0c commit ba56be8

File tree

2 files changed

+14
-44
lines changed

2 files changed

+14
-44
lines changed

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

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

3+
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
4+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
5+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
6+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
7+
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
8+
import static java.util.Collections.singletonList;
9+
310
import com.grack.nanojson.JsonArray;
411
import com.grack.nanojson.JsonObject;
512
import com.grack.nanojson.JsonParser;
613
import com.grack.nanojson.JsonParserException;
14+
715
import org.jsoup.Jsoup;
816
import org.jsoup.nodes.Document;
917
import org.jsoup.nodes.Element;
@@ -23,7 +31,6 @@
2331
import org.schabi.newpipe.extractor.utils.Parser.RegexException;
2432
import org.schabi.newpipe.extractor.utils.Utils;
2533

26-
import javax.annotation.Nonnull;
2734
import java.io.IOException;
2835
import java.net.MalformedURLException;
2936
import java.net.URL;
@@ -35,13 +42,9 @@
3542
import java.util.HashMap;
3643
import java.util.List;
3744

38-
import static java.util.Collections.singletonList;
39-
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
40-
import static org.schabi.newpipe.extractor.utils.Utils.*;
45+
import javax.annotation.Nonnull;
4146

4247
public class SoundcloudParsingHelper {
43-
static final String HARDCODED_CLIENT_ID =
44-
"0vyDB4rxVEprGutWT0xQ2VZhYpVZxku4"; // Updated on 2022-02-11
4548
private static String clientId;
4649
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
4750

@@ -52,12 +55,6 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
5255
if (!isNullOrEmpty(clientId)) return clientId;
5356

5457
final Downloader dl = NewPipe.getDownloader();
55-
clientId = HARDCODED_CLIENT_ID;
56-
if (checkIfHardcodedClientIdIsValid()) {
57-
return clientId;
58-
} else {
59-
clientId = null;
60-
}
6158

6259
final Response download = dl.get("https://soundcloud.com");
6360
final String responseBody = download.responseBody();
@@ -89,14 +86,6 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
8986
throw new ExtractionException("Couldn't extract client id");
9087
}
9188

92-
static boolean checkIfHardcodedClientIdIsValid() throws IOException, ReCaptchaException {
93-
final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2_URL + "?client_id="
94-
+ HARDCODED_CLIENT_ID).responseCode();
95-
// If the response code is 404, it means that the client_id is valid; otherwise,
96-
// it should be not valid
97-
return responseCode == 404;
98-
}
99-
10089
public static OffsetDateTime parseDateFrom(final String textualUploadDate)
10190
throws ParsingException {
10291
try {

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,28 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

3-
import org.junit.jupiter.api.Assertions;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
45
import org.junit.jupiter.api.BeforeAll;
56
import org.junit.jupiter.api.Test;
67
import org.schabi.newpipe.downloader.DownloaderTestImpl;
78
import org.schabi.newpipe.extractor.NewPipe;
8-
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
9-
10-
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.assertTrue;
12-
13-
import java.io.IOException;
149

15-
public class SoundcloudParsingHelperTest {
10+
class SoundcloudParsingHelperTest {
1611
@BeforeAll
1712
public static void setUp() {
1813
NewPipe.init(DownloaderTestImpl.getInstance());
1914
}
2015

2116
@Test
22-
public void assertThatHardcodedClientIdIsValid() throws Exception {
23-
assertTrue(SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid(),
24-
"Hardcoded client id is not valid anymore");
25-
}
26-
27-
@Test
28-
public void assertHardCodedClientIdMatchesCurrentClientId() throws IOException, ExtractionException {
29-
assertEquals(
30-
SoundcloudParsingHelper.HARDCODED_CLIENT_ID,
31-
SoundcloudParsingHelper.clientId(),
32-
"Hardcoded client doesn't match extracted clientId");
33-
}
34-
35-
@Test
36-
public void resolveUrlWithEmbedPlayerTest() throws Exception {
17+
void resolveUrlWithEmbedPlayerTest() throws Exception {
3718
assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743"));
3819
assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/16069159"));
3920
assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api-v2.soundcloud.com/users/26057743"));
4021
assertEquals("https://soundcloud.com/nocopyrightsounds", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api-v2.soundcloud.com/users/16069159"));
4122
}
4223

4324
@Test
44-
public void resolveIdWithWidgetApiTest() throws Exception {
25+
void resolveIdWithWidgetApiTest() throws Exception {
4526
assertEquals("26057743", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/trapcity"));
4627
assertEquals("16069159", SoundcloudParsingHelper.resolveIdWithWidgetApi("https://soundcloud.com/nocopyrightsounds"));
4728
}

0 commit comments

Comments
 (0)