From cc320c119bc48cdcc198010281b7c0781d9ab9e4 Mon Sep 17 00:00:00 2001 From: MrIkso Date: Mon, 30 Sep 2024 22:43:14 +0300 Subject: [PATCH] fix: fixed parsing videos from monstro.site players --- .../anitube/app/extractors/csstExtractor.java | 5 +++-- .../com/mrikso/anitube/app/utils/StringUtils.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/mrikso/anitube/app/extractors/csstExtractor.java b/app/src/main/java/com/mrikso/anitube/app/extractors/csstExtractor.java index a20e462..7b49d7e 100644 --- a/app/src/main/java/com/mrikso/anitube/app/extractors/csstExtractor.java +++ b/app/src/main/java/com/mrikso/anitube/app/extractors/csstExtractor.java @@ -34,8 +34,9 @@ public Single> parse() { return Single.fromCallable(() -> { extract(); Gson gson = new Gson(); - String json = ParserUtils.getMatcherResult( - PLAYER_JS_PATTERN, getDocument().data(), 1); + String json = StringUtils.toValidJson(ParserUtils.getMatcherResult( + PLAYER_JS_PATTERN, getDocument().data(), 1)); + // int lastIndex = json.lastIndexOf(","); // if (lastIndex >= 0) { // json = json.substring(0, lastIndex) + "}"; diff --git a/app/src/main/java/com/mrikso/anitube/app/utils/StringUtils.java b/app/src/main/java/com/mrikso/anitube/app/utils/StringUtils.java index fb1e8e4..5b3719c 100644 --- a/app/src/main/java/com/mrikso/anitube/app/utils/StringUtils.java +++ b/app/src/main/java/com/mrikso/anitube/app/utils/StringUtils.java @@ -3,6 +3,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import org.json.JSONObject; + public class StringUtils { public static String removeLastChar(String str) { return removeChars(str, 1); @@ -23,4 +25,16 @@ public static String guessFileExtension(@NonNull String filename) { } return null; } + + public static String toValidJson(@NonNull String input) { + input = input.replaceAll("'", "\"") + .replaceAll("(\\w+):(?