Skip to content

Commit 86308d0

Browse files
committed
Use a lightweight request to check if the client_id is valid
Request the api-v2 host with the client_id instead of checking if the streams of a SoundCloud track are not empty: if it is valid, the API returns 404, otherwise it should return 401.
1 parent c5c1905 commit 86308d0

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class SoundcloudParsingHelper {
4444
private static final String HARDCODED_CLIENT_ID =
4545
"NcIaRZItQCNQp3Vq9Plvzf7tvjmVJnF6"; // Updated on 26/04/21
4646
private static String clientId;
47+
public static final String SOUNDCLOUD_API_V2 = "https://api-v2.soundcloud.com/";
4748

4849
private SoundcloudParsingHelper() {
4950
}
@@ -88,17 +89,12 @@ public static synchronized String clientId() throws ExtractionException, IOExcep
8889
throw new ExtractionException("Couldn't extract client id");
8990
}
9091

91-
static boolean checkIfHardcodedClientIdIsValid() {
92-
try {
93-
SoundcloudStreamExtractor e = (SoundcloudStreamExtractor) SoundCloud
94-
.getStreamExtractor(
95-
"https://soundcloud.com/liluzivert/do-what-i-want-produced-by-maaly-raw-don-cannon");
96-
e.fetchPage();
97-
return !e.getAudioStreams().isEmpty();
98-
} catch (final Exception ignored) {
99-
// No need to throw an exception here. If something went wrong, the client_id is wrong
100-
return false;
101-
}
92+
static boolean checkIfHardcodedClientIdIsValid() throws IOException, ReCaptchaException {
93+
final int responseCode = NewPipe.getDownloader().get(SOUNDCLOUD_API_V2 + "?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;
10298
}
10399

104100
public static OffsetDateTime parseDateFrom(final String textualUploadDate)
@@ -123,7 +119,7 @@ public static OffsetDateTime parseDateFrom(final String textualUploadDate)
123119
*/
124120
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
125121
throws IOException, ExtractionException {
126-
final String apiUrl = "https://api-v2.soundcloud.com/resolve" + "?url="
122+
final String apiUrl = SOUNDCLOUD_API_V2 + "resolve" + "?url="
127123
+ URLEncoder.encode(url, UTF_8) + "&client_id=" + clientId();
128124

129125
try {

0 commit comments

Comments
 (0)