|
11 | 11 |
|
12 | 12 | import org.apache.logging.log4j.LogManager;
|
13 | 13 | import org.apache.logging.log4j.Logger;
|
14 |
| -import org.json.JSONObject; |
| 14 | +import org.json.JSONArray; |
15 | 15 | import org.jsoup.nodes.Document;
|
16 | 16 | import org.jsoup.nodes.Element;
|
17 | 17 |
|
@@ -98,32 +98,42 @@ public boolean canRip(URL url) {
|
98 | 98 | return m.matches();
|
99 | 99 | }
|
100 | 100 |
|
| 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 | + } |
101 | 110 |
|
102 | 111 | @Override
|
103 | 112 | public List<String> getURLsFromPage(Document doc) {
|
104 | 113 | List<String> result = new ArrayList<>();
|
105 | 114 | for (Element script : doc.select("script")) {
|
106 |
| - if (script.data().contains("var images = ")) { |
| 115 | + if (script.data().contains("imgHttps")) { |
107 | 116 | 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); |
119 | 118 |
|
| 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 | + } |
120 | 129 | }
|
121 | 130 | }
|
122 | 131 | return result;
|
123 | 132 | }
|
124 | 133 |
|
125 | 134 | @Override
|
126 | 135 | public void downloadURL(URL url, int index) {
|
| 136 | + sleep(500); |
127 | 137 | addURLToDownload(url, getPrefix(index));
|
128 | 138 | }
|
129 | 139 | }
|
0 commit comments