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
This commit is contained in:
TobiGr 2020-03-16 19:42:35 +01:00
parent dc20f2aa0c
commit efad0be99f
2 changed files with 6 additions and 6 deletions

View file

@ -42,7 +42,7 @@ public class SoundcloudParsingHelper {
Downloader dl = NewPipe.getDownloader();
clientId = HARDCODED_CLIENT_ID;
if (checkIfHardcodedClientIdIsValid(dl)) {
if (checkIfHardcodedClientIdIsValid()) {
return clientId;
}
@ -73,11 +73,11 @@ public class SoundcloudParsingHelper {
throw new ExtractionException("Couldn't extract client id");
}
static boolean checkIfHardcodedClientIdIsValid(Downloader dl) {
final String apiUrl = "https://api.soundcloud.com/connect?client_id=" + HARDCODED_CLIENT_ID;
static boolean checkIfHardcodedClientIdIsValid() {
try {
// Should return 200 to indicate that the client id is valid, a 401 is returned otherwise.
return dl.head(apiUrl).responseCode() == 200;
SoundcloudStreamExtractor e = (SoundcloudStreamExtractor) SoundCloud
.getStreamExtractor("https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
return e.getAudioStreams().size() >= 1;
} catch (Exception ignored) {
// No need to throw an exception here. If something went wrong, the client_id is wrong
return false;

View file

@ -17,7 +17,7 @@ public class SoundcloudParsingHelperTest {
@Test
public void assertThatHardcodedClientIdIsValid() throws Exception {
assertTrue("Hardcoded client id is not valid anymore",
SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid(DownloaderTestImpl.getInstance()));
SoundcloudParsingHelper.checkIfHardcodedClientIdIsValid());
}
@Test