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+):(?