+ if (isPool(source)) {
+ return getChaptersPool(source, in, pg);
+ } else if (isSearch(source)) {
+ return getChaptersSearch(source, in, pg);
+ }
+
+ return new LinkedList<Entry<String, URL>>();
+ }
+
+ private List<Entry<String, URL>> getChaptersSearch(URL source,
+ InputStream in, Progress pg) throws IOException {
+ List<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
+
+ String search = source.getPath();
+ if (search.endsWith("/")) {
+ search = search.substring(0, search.length() - 1);
+ }
+
+ int pos = search.lastIndexOf('/');
+ if (pos >= 0) {
+ search = search.substring(pos + 1);
+ }
+
+ String baseUrl = "https://e621.net/post/index/";
+ if (source.getHost().contains("e926")) {
+ baseUrl = baseUrl.replace("e621", "e926");
+ }
+
+ for (int i = 1; true; i++) {
+ URL url = new URL(baseUrl + i + "/" + search + "/");
+ try {
+ InputStream pageI = Instance.getCache().open(url, this, false);
+ try {
+ if (getLine(pageI, "No posts matched your search.", 0) != null)
+ break;
+ urls.add(new AbstractMap.SimpleEntry<String, URL>("Page "
+ + Integer.toString(i), url));
+ } finally {
+ pageI.close();
+ }
+ } catch (Exception e) {
+ break;
+ }
+ }
+
+ // They are sorted in reverse order on the website
+ Collections.reverse(urls);
+ return urls;
+ }
+
+ private List<Entry<String, URL>> getChaptersPool(URL source,
+ InputStream in, Progress pg) throws IOException {