X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FE621.java;h=39bbe867d9eb2cdfc630c80df9393bc9bc47aba4;hb=ba9b5cc4a752a651f1896b14c04cb6ade7746f97;hp=94010a73ae4b61165598b35b4f7ff8743b4b2e41;hpb=0013f760d69fd7db2b298c3da5d89bc0b102eabf;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index 94010a7..39bbe86 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -17,6 +17,7 @@ import java.util.Map.Entry; import org.jsoup.helper.DataUtil; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; @@ -100,16 +101,25 @@ class E621 extends BasicSupport { @Override protected List> getChapters(Progress pg) throws IOException { + List> chapters = new LinkedList>(); + if (isPool(getSource())) { String baseUrl = "https://e621.net/" + getSource().getPath() + "?page="; - return getChapters(getSource(), pg, baseUrl, ""); + chapters = getChapters(getSource(), pg, baseUrl, ""); } else if (isSearchOrSet(getSource())) { String baseUrl = "https://e621.net/posts/?page="; String search = "&tags=" + getTagsFromUrl(getSource()); - return getChapters(getSource(), pg, baseUrl, search); + + chapters = getChapters(getSource(), pg, + baseUrl, search); } - return new LinkedList>(); + // sets and some pools are sorted in reverse order on the website + if (getSource().getPath().startsWith("/posts")) { + Collections.reverse(chapters); + } + + return chapters; } private List> getChapters(URL source, Progress pg, String baseUrl, String parameters) @@ -123,7 +133,7 @@ class E621 extends BasicSupport { for (int i = 1; true; i++) { URL url = new URL(baseUrl + i + parameters); try { - InputStream pageI = Instance.getCache().open(url, this, false); + InputStream pageI = Instance.getInstance().getCache().open(url, this, false); try { if (IOUtils.readSmallStream(pageI).contains("Nobody here but us chickens!")) { break; @@ -137,8 +147,6 @@ class E621 extends BasicSupport { } } - // They are sorted in reverse order on the website - Collections.reverse(urls); return urls; } @@ -146,7 +154,15 @@ class E621 extends BasicSupport { protected String getChapterContent(URL chapUrl, int number, Progress pg) throws IOException { StringBuilder builder = new StringBuilder(); Document chapterNode = loadDocument(chapUrl); - for (Element el : chapterNode.getElementsByTag("article")) { + + Elements articles = chapterNode.getElementsByTag("article"); + + // sets and some pools are sorted in reverse order on the website + if (getSource().getPath().startsWith("/posts")) { + Collections.reverse(articles); + } + + for (Element el : articles) { builder.append("["); builder.append(el.attr("data-file-url")); builder.append("]
"); @@ -159,7 +175,7 @@ class E621 extends BasicSupport { protected URL getCanonicalUrl(URL source) { if (isSetOriginalUrl(source)) { try { - Document doc = DataUtil.load(Instance.getCache().open(source, this, false), "UTF-8", source.toString()); + Document doc = DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", source.toString()); for (Element shortname : doc.getElementsByClass("set-shortname")) { for (Element el : shortname.getElementsByTag("a")) { if (!el.attr("href").isEmpty()) @@ -167,7 +183,7 @@ class E621 extends BasicSupport { } } } catch (IOException e) { - Instance.getTraceHandler().error(e); + Instance.getInstance().getTraceHandler().error(e); } }