Skip to content

Commit

Permalink
Fix BatoRipper: update to new site code (Fix #2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
metaprime committed Feb 2, 2025
1 parent f4ea0fe commit f2c9974
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/main/java/com/rarchives/ripme/ripper/rippers/BatoRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.json.JSONArray;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

Expand Down Expand Up @@ -98,32 +98,42 @@ public boolean canRip(URL url) {
return m.matches();
}

public String scanForImageList(Pattern p, String scriptData) {
for (String line : scriptData.split("\n")) {
Matcher m = p.matcher(line.strip());
if (m.matches()) {
return m.group(1);
}
}
return "[]";
}

@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>();
for (Element script : doc.select("script")) {
if (script.data().contains("var images = ")) {
if (script.data().contains("imgHttps")) {
String s = script.data();
s = s.replaceAll("var seriesId = \\d+;", "");
s = s.replaceAll("var chapterId = \\d+;", "");
s = s.replaceAll("var pages = \\d+;", "");
s = s.replaceAll("var page = \\d+;", "");
s = s.replaceAll("var prevCha = null;", "");
s = s.replaceAll("var nextCha = \\.*;", "");
String json = s.replaceAll("var images = ", "").replaceAll(";", "");
JSONObject images = new JSONObject(json);
for (int i = 1; i < images.length() +1; i++) {
result.add(images.getString(Integer.toString(i)));
}
logger.info("Script data: " + s);

Pattern p = Pattern.compile(".*imgHttps = (\\[\"[^\\];]*\"\\]);.*");
Matcher m = p.matcher(s);
String json = scanForImageList(p, s);

logger.info("JSON: " + json);

JSONArray images = new JSONArray(json);
for (int i = 0; i < images.length(); i++) {
result.add(images.getString(i));
}
}
}
return result;
}

@Override
public void downloadURL(URL url, int index) {
sleep(500);
addURLToDownload(url, getPrefix(index));
}
}

0 comments on commit f2c9974

Please sign in to comment.