From be9a6f931ca1c517aa4eaf1eb172b593e24d9238 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Fri, 16 Oct 2020 20:27:40 +0200 Subject: [PATCH] Fix parsing new ytInitialData --- .../extractor/services/youtube/YoutubeParsingHelper.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 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 e124d0208..af10efa22 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 @@ -197,8 +197,13 @@ public class YoutubeParsingHelper { public static JsonObject getInitialData(String html) throws ParsingException { try { - String initialData = Parser.matchGroup1("window\\[\"ytInitialData\"\\]\\s*=\\s*(\\{.*?\\});", html); - return JsonParser.object().from(initialData); + try { + final String initialData = Parser.matchGroup1("window\\[\"ytInitialData\"\\]\\s*=\\s*(\\{.*?\\});", html); + return JsonParser.object().from(initialData); + } catch (Parser.RegexException e) { + final String initialData = Parser.matchGroup1("var\\s*ytInitialData\\s*=\\s*(\\{.*?\\});", html); + return JsonParser.object().from(initialData); + } } catch (JsonParserException | Parser.RegexException e) { throw new ParsingException("Could not get ytInitialData", e); }