From 021e6c4b41fabb57a9eefb2e9604e2f275b5c3cc Mon Sep 17 00:00:00 2001 From: wb9688 Date: Sun, 6 Aug 2017 11:18:58 +0200 Subject: [PATCH] Cache clientId --- .../soundcloud/SoundcloudParsingHelper.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java index 45af5c29e..a39237306 100644 --- a/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java +++ b/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java @@ -22,16 +22,20 @@ public class SoundcloudParsingHelper { private SoundcloudParsingHelper() { } - public static final String clientId() throws ReCaptchaException, IOException, RegexException { - Downloader dl = NewPipe.getDownloader(); + private static String clientId; - String response = dl.download("https://soundcloud.com"); - Document doc = Jsoup.parse(response); + public static String clientId() throws ReCaptchaException, IOException, RegexException { + if (clientId.isEmpty()) { + Downloader dl = NewPipe.getDownloader(); - Element jsElement = doc.select("script[src^=https://a-v2.sndcdn.com/assets/app]").first(); - String js = dl.download(jsElement.attr("src")); + String response = dl.download("https://soundcloud.com"); + Document doc = Jsoup.parse(response); - String clientId = Parser.matchGroup1(",client_id:\"(.*?)\"", js); + Element jsElement = doc.select("script[src^=https://a-v2.sndcdn.com/assets/app]").first(); + String js = dl.download(jsElement.attr("src")); + + clientId = Parser.matchGroup1(",client_id:\"(.*?)\"", js); + } return clientId; } @@ -76,5 +80,4 @@ public class SoundcloudParsingHelper { throw new ParsingException(e.getMessage(), e); } } - }