X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=supported%2FE621.java;h=602cd36309250e03de7291c4f46784b7171ccc93;hb=36c35b92f704ed40f3ce80501dc96cce73d39ceb;hp=de754c8b843da881bf1e34419a7491997ac8d201;hpb=a351d69d95da8563d49e6a4080035fcd69ee1c48;p=nikiroo-utils.git diff --git a/supported/E621.java b/supported/E621.java index de754c8..602cd36 100644 --- a/supported/E621.java +++ b/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,20 +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()); - // sets are sorted in reverse order on the website - List> urls = getChapters(getSource(), pg, + + chapters = getChapters(getSource(), pg, baseUrl, search); - Collections.reverse(urls); - return urls; } - 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) @@ -148,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,6 +173,25 @@ class E621 extends BasicSupport { @Override protected URL getCanonicalUrl(URL source) { + // Convert search-pools into proper pools + if (source.getPath().equals("/posts") && source.getQuery() != null + && source.getQuery().startsWith("tags=pool%3A")) { + String poolNumber = source.getQuery() + .substring("tags=pool%3A".length()); + try { + Integer.parseInt(poolNumber); + String base = source.getProtocol() + "://" + source.getHost(); + if (source.getPort() != -1) { + base = base + ":" + source.getPort(); + } + source = new URL(base + "/pools/" + poolNumber); + } catch (NumberFormatException e) { + // Not a simple pool, skip + } catch (MalformedURLException e) { + // Cannot happen + } + } + if (isSetOriginalUrl(source)) { try { Document doc = DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", source.toString()); @@ -214,19 +247,19 @@ class E621 extends BasicSupport { title = el.text().trim(); } - for (String s : new String[] { "e621", "-", "e621" }) { + for (String s : new String[] { "e621", "-", "e621", "Pool", "-" }) { if (title.startsWith(s)) { title = title.substring(s.length()).trim(); } if (title.endsWith(s)) { title = title.substring(0, title.length() - s.length()).trim(); } - } if (isSearchOrSet(getSource())) { title = title.isEmpty() ? "e621" : "[e621] " + title; } + return title; }