Skip to content

Commit

Permalink
fix: fixed parsing videos from monstro.site players
Browse files Browse the repository at this point in the history
  • Loading branch information
MrIkso committed Sep 30, 2024
1 parent 0d37957 commit cc320c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public Single<Pair<LoadState, VideoLinksModel>> 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) + "}";
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/mrikso/anitube/app/utils/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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+):(?<!https:|http:)", "\"$1\":")
.replaceAll(",\\s*\\}", "}");
try {
JSONObject jsonObject = new JSONObject(input);
return jsonObject.toString(4);
} catch (Exception e) {
throw new IllegalStateException("Invalid JSON input");
}
}
}

0 comments on commit cc320c1

Please sign in to comment.