From efad0be99ffaeff71900bb206a1216ece7c0a14e Mon Sep 17 00:00:00 2001 From: TobiGr Date: Mon, 16 Mar 2020 19:42:35 +0100 Subject: [PATCH] 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 --- .../services/soundcloud/SoundcloudParsingHelper.java | 10 +++++----- .../soundcloud/SoundcloudParsingHelperTest.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java index b8f6af246..11cd609c6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java @@ -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; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java index 16089aab1..bbbcb8618 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelperTest.java @@ -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