Skip to content

Commit f2c9974

Browse files
committed
Fix BatoRipper: update to new site code (Fix #2095)
1 parent f4ea0fe commit f2c9974

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

src/main/java/com/rarchives/ripme/ripper/rippers/BatoRipper.java

+23-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
14-
import org.json.JSONObject;
14+
import org.json.JSONArray;
1515
import org.jsoup.nodes.Document;
1616
import org.jsoup.nodes.Element;
1717

@@ -98,32 +98,42 @@ public boolean canRip(URL url) {
9898
return m.matches();
9999
}
100100

101+
public String scanForImageList(Pattern p, String scriptData) {
102+
for (String line : scriptData.split("\n")) {
103+
Matcher m = p.matcher(line.strip());
104+
if (m.matches()) {
105+
return m.group(1);
106+
}
107+
}
108+
return "[]";
109+
}
101110

102111
@Override
103112
public List<String> getURLsFromPage(Document doc) {
104113
List<String> result = new ArrayList<>();
105114
for (Element script : doc.select("script")) {
106-
if (script.data().contains("var images = ")) {
115+
if (script.data().contains("imgHttps")) {
107116
String s = script.data();
108-
s = s.replaceAll("var seriesId = \\d+;", "");
109-
s = s.replaceAll("var chapterId = \\d+;", "");
110-
s = s.replaceAll("var pages = \\d+;", "");
111-
s = s.replaceAll("var page = \\d+;", "");
112-
s = s.replaceAll("var prevCha = null;", "");
113-
s = s.replaceAll("var nextCha = \\.*;", "");
114-
String json = s.replaceAll("var images = ", "").replaceAll(";", "");
115-
JSONObject images = new JSONObject(json);
116-
for (int i = 1; i < images.length() +1; i++) {
117-
result.add(images.getString(Integer.toString(i)));
118-
}
117+
logger.info("Script data: " + s);
119118

119+
Pattern p = Pattern.compile(".*imgHttps = (\\[\"[^\\];]*\"\\]);.*");
120+
Matcher m = p.matcher(s);
121+
String json = scanForImageList(p, s);
122+
123+
logger.info("JSON: " + json);
124+
125+
JSONArray images = new JSONArray(json);
126+
for (int i = 0; i < images.length(); i++) {
127+
result.add(images.getString(i));
128+
}
120129
}
121130
}
122131
return result;
123132
}
124133

125134
@Override
126135
public void downloadURL(URL url, int index) {
136+
sleep(500);
127137
addURLToDownload(url, getPrefix(index));
128138
}
129139
}

0 commit comments

Comments
 (0)