Skip to content

Commit efad0be

Browse files
committed
Test if the extractor can get AudiStreams with the hard-coded cliend_id
SoundCloud client_id are changed on a regular basis now. We might want to remove the hardcoded id completely on a later point of time when client_id is changed to often
1 parent dc20f2a commit efad0be

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

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
@@ -42,7 +42,7 @@ public static String clientId() throws ExtractionException, IOException {
4242

4343
Downloader dl = NewPipe.getDownloader();
4444
clientId = HARDCODED_CLIENT_ID;
45-
if (checkIfHardcodedClientIdIsValid(dl)) {
45+
if (checkIfHardcodedClientIdIsValid()) {
4646
return clientId;
4747
}
4848

@@ -73,11 +73,11 @@ public static String clientId() throws ExtractionException, IOException {
7373
throw new ExtractionException("Couldn't extract client id");
7474
}
7575

76-
static boolean checkIfHardcodedClientIdIsValid(Downloader dl) {
77-
final String apiUrl = "https://api.soundcloud.com/connect?client_id=" + HARDCODED_CLIENT_ID;
76+
static boolean checkIfHardcodedClientIdIsValid() {
7877
try {
79-
// Should return 200 to indicate that the client id is valid, a 401 is returned otherwise.
80-
return dl.head(apiUrl).responseCode() == 200;
78+
SoundcloudStreamExtractor e = (SoundcloudStreamExtractor) SoundCloud
79+
.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
80+
return e.getAudioStreams().size() >= 1;
8181
} catch (Exception ignored) {
8282
// No need to throw an exception here. If something went wrong, the client_id is wrong
8383
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void setUp() {
1717
@Test
1818
public void assertThatHardcodedClientIdIsValid() throws Exception {
1919
assertTrue("Hardcoded client id is not valid anymore",
20-
SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid(DownloaderTestImpl.getInstance()));
20+
SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid());
2121
}
2222

2323
@Test

0 commit comments

Comments
 (0)