From 667dce034c1aa5a2378b2e4b5a1a9e2dc67c14f5 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Sun, 26 Jul 2020 13:14:25 +0200 Subject: [PATCH] Only use fallback methods for clientVersion when clientVersion hasn't been successfully extracted yet --- .../extractor/services/youtube/YoutubeParsingHelper.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index f9d896d86..e124d0208 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -216,7 +216,7 @@ public class YoutubeParsingHelper { return response.length() > 50; // ensure to have a valid response } - private static void getClientVersionAndKey() throws IOException, ExtractionException { + private static void extractClientVersionAndKey() throws IOException, ExtractionException { final String url = "https://www.youtube.com/results?search_query=test"; final String html = getDownloader().get(url).responseBody(); final JsonObject initialData = getInitialData(html); @@ -259,11 +259,12 @@ public class YoutubeParsingHelper { contextClientVersion = Parser.matchGroup1(pattern, html); if (!isNullOrEmpty(contextClientVersion)) { clientVersion = contextClientVersion; + break; } } catch (Parser.RegexException ignored) { } } - if (shortClientVersion != null) { + if (!isNullOrEmpty(clientVersion) && !isNullOrEmpty(shortClientVersion)) { clientVersion = shortClientVersion; } @@ -283,7 +284,7 @@ public class YoutubeParsingHelper { if (!isNullOrEmpty(clientVersion)) return clientVersion; if (isHardcodedClientVersionValid()) return clientVersion = HARDCODED_CLIENT_VERSION; - getClientVersionAndKey(); + extractClientVersionAndKey(); if (isNullOrEmpty(key)) throw new ParsingException("Could not extract client version"); return clientVersion; } @@ -294,7 +295,7 @@ public class YoutubeParsingHelper { public static String getKey() throws IOException, ExtractionException { if (!isNullOrEmpty(key)) return key; - getClientVersionAndKey(); + extractClientVersionAndKey(); if (isNullOrEmpty(key)) throw new ParsingException("Could not extract key"); return key; }