From f8309d546a13736b89c8a41e1eaa9d4f4ee5fea3 Mon Sep 17 00:00:00 2001 From: TiA4f8R <74829229+TiA4f8R@users.noreply.github.com> Date: Thu, 12 Aug 2021 18:26:43 +0200 Subject: [PATCH] [YouTube] Consolidate current regexes of the cipher decryption function Also add more regexes --- .../extractors/YoutubeStreamExtractor.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 387ba4f75..43d765c85 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -279,12 +279,12 @@ public class YoutubeStreamExtractor extends StreamExtractor { return Long.parseLong(duration); } catch (final Exception e) { if (desktopStreamingData != null) { - final JsonArray adaptiveFormats = desktopStreamingData.getArray("adaptiveFormats"); + final JsonArray adaptiveFormats = desktopStreamingData.getArray(ADAPTIVE_FORMATS); final String durationMs = adaptiveFormats.getObject(0) .getString("approxDurationMs"); return Math.round(Long.parseLong(durationMs) / 1000f); } else if (mobileStreamingData != null) { - final JsonArray adaptiveFormats = mobileStreamingData.getArray("adaptiveFormats"); + final JsonArray adaptiveFormats = mobileStreamingData.getArray(ADAPTIVE_FORMATS); final String durationMs = adaptiveFormats.getObject(0) .getString("approxDurationMs"); return Math.round(Long.parseLong(durationMs) / 1000f); @@ -685,9 +685,11 @@ public class YoutubeStreamExtractor extends StreamExtractor { private static final String DEOBFUSCATION_FUNC_NAME = "deobfuscate"; private static final String[] REGEXES = { - "(?:\\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)", + "(?:\\b|[^a-zA-Z0-9$])([a-zA-Z0-9$]{2,})\\s*=\\s*function\\(\\s*a\\s*\\)\\s*\\{\\s*a\\s*=\\s*a\\.split\\(\\s*\"\"\\s*\\)", + "\\bm=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(h\\.s\\)\\)", + "\\bc&&\\(c=([a-zA-Z0-9$]{2,})\\(decodeURIComponent\\(c\\)\\)", "([\\w$]+)\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;", - "\\b([\\w$]{2})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;", + "\\b([\\w$]{2,})\\s*=\\s*function\\((\\w+)\\)\\{\\s*\\2=\\s*\\2\\.split\\(\"\"\\)\\s*;", "\\bc\\s*&&\\s*d\\.set\\([^,]+\\s*,\\s*(:encodeURIComponent\\s*\\()([a-zA-Z0-9$]+)\\(" }; private static final String STS_REGEX = "signatureTimestamp[=:](\\d+)"; @@ -931,8 +933,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { private boolean isCipherProtectedContent() { if (desktopStreamingData != null) { - if (desktopStreamingData.has("adaptiveFormats")) { - final JsonArray adaptiveFormats = desktopStreamingData.getArray("adaptiveFormats"); + if (desktopStreamingData.has(ADAPTIVE_FORMATS)) { + final JsonArray adaptiveFormats = desktopStreamingData.getArray(ADAPTIVE_FORMATS); if (!isNullOrEmpty(adaptiveFormats)) { for (final Object adaptiveFormat : adaptiveFormats) { final JsonObject adaptiveFormatJsonObject = ((JsonObject) adaptiveFormat); @@ -943,8 +945,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { } } } - if (desktopStreamingData.has("formats")) { - final JsonArray formats = desktopStreamingData.getArray("formats"); + if (desktopStreamingData.has(FORMATS)) { + final JsonArray formats = desktopStreamingData.getArray(FORMATS); if (!isNullOrEmpty(formats)) { for (final Object format : formats) { final JsonObject formatJsonObject = ((JsonObject) format);