Skip to content

Commit ddd563f

Browse files
mauriciocolliTobiGr
authored andcommitted
[SoundCloud] Add test for hardcoded client id
1 parent 4fc18a6 commit ddd563f

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
3232

3333
public class SoundcloudParsingHelper {
34+
private static final String HARDCODED_CLIENT_ID = "LHzSAKe8eP9Yy3FgBugfBapRPLncO6Ng"; // Updated on 22/10/19
3435
private static String clientId;
3536

3637
private SoundcloudParsingHelper() {
@@ -40,11 +41,8 @@ public static String clientId() throws ExtractionException, IOException {
4041
if (clientId != null && !clientId.isEmpty()) return clientId;
4142

4243
Downloader dl = NewPipe.getDownloader();
43-
clientId = "LHzSAKe8eP9Yy3FgBugfBapRPLncO6Ng"; // Updated on 22/10/19
44-
final String apiUrl = "https://api.soundcloud.com/connect?client_id=" + clientId;
45-
// Should return 200 to indicate that the client id is valid, a 401 is returned otherwise.
46-
// In that case, the fallback method is used.
47-
if (dl.head(apiUrl).getResponseCode() == 200) {
44+
clientId = HARDCODED_CLIENT_ID;
45+
if (checkIfHardcodedClientIdIsValid(dl)) {
4846
return clientId;
4947
}
5048

@@ -75,6 +73,12 @@ public static String clientId() throws ExtractionException, IOException {
7573
throw new ExtractionException("Couldn't extract client id");
7674
}
7775

76+
static boolean checkIfHardcodedClientIdIsValid(Downloader dl) throws IOException, ReCaptchaException {
77+
final String apiUrl = "https://api.soundcloud.com/connect?client_id=" + HARDCODED_CLIENT_ID;
78+
// Should return 200 to indicate that the client id is valid, a 401 is returned otherwise.
79+
return dl.head(apiUrl).getResponseCode() == 200;
80+
}
81+
7882
public static String toDateString(String time) throws ParsingException {
7983
try {
8084
Date date;

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

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

3-
import org.junit.Assert;
4-
import org.junit.BeforeClass;
5-
import org.junit.Test;
3+
import org.junit.*;
64
import org.schabi.newpipe.Downloader;
75
import org.schabi.newpipe.extractor.NewPipe;
86
import org.schabi.newpipe.extractor.utils.Localization;
97

8+
import static org.junit.Assert.*;
9+
1010
public class SoundcloudParsingHelperTest {
1111
@BeforeClass
1212
public static void setUp() {
1313
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
1414
}
1515

16+
@Test
17+
public void assertThatHardcodedClientIdIsValid() throws Exception {
18+
assertTrue("Hardcoded client id is not valid anymore",
19+
SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid(Downloader.getInstance()));
20+
}
21+
1622
@Test
1723
public void resolveUrlWithEmbedPlayerTest() throws Exception {
1824
Assert.assertEquals("https://soundcloud.com/trapcity", SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/26057743"));

0 commit comments

Comments
 (0)