X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FE621.java;h=d6cbad40744743f27550e66b8f3357caa1be2591;hb=9b863b20370118c95c6801b73dda951c7e507871;hp=44621b9a79fe31ea10773dd6ca3d88b158a092e6;hpb=b5e9855b962842b306c17688c1c793dc1378ea62;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index 44621b9..d6cbad4 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -3,11 +3,14 @@ package be.nikiroo.fanfix.supported; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.AbstractMap; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.AbstractMap.SimpleEntry; @@ -130,12 +133,12 @@ class E621 extends BasicSupport_Deprecated { } private Image getCover(URL source, InputStream in) throws IOException { - // No cover on searches (/post/) - if (isSearch(source)) - return null; + URL urlForCover = source; + if (isPool(source)) { + urlForCover = new URL(source.toString() + "?page=1"); + } - String images = getChapterContent(new URL(source.toString() + "?page=" - + 1), in, 1, null); + String images = getChapterContent(urlForCover, in, 1, null); if (!images.isEmpty()) { int pos = images.indexOf("
"); if (pos >= 0) { @@ -284,8 +287,8 @@ class E621 extends BasicSupport_Deprecated { try { if (getLine(pageI, "No posts matched your search.", 0) != null) break; - urls.add(new AbstractMap.SimpleEntry(Integer - .toString(i), url)); + urls.add(new AbstractMap.SimpleEntry("Page " + + Integer.toString(i), url)); } finally { pageI.close(); } @@ -294,6 +297,8 @@ class E621 extends BasicSupport_Deprecated { } } + // They are sorted in reverse order on the website + Collections.reverse(urls); return urls; } @@ -371,11 +376,33 @@ class E621 extends BasicSupport_Deprecated { return builder.toString(); } + @Override + protected URL getCanonicalUrl(URL source) { + if (isSearch(source)) { + // /post?tags=tag1+tag2 -> ../post/index/1/tag1%32tag2 + String key = "post?tags="; + if (source.toString().contains(key)) { + int pos = source.toString().indexOf(key); + String tags = source.toString().substring(pos + key.length()); + tags = tags.replace("+", "%32"); + try { + return new URL(source.toString().substring(0, pos) + + "post/index/1/" + tags); + } catch (MalformedURLException e) { + Instance.getTraceHandler().error(e); + } + } + } + return super.getCanonicalUrl(source); + } + private boolean isPool(URL url) { return url.getPath().startsWith("/pool/"); } private boolean isSearch(URL url) { - return url.getPath().startsWith("/post/index/"); + return url.getPath().startsWith("/post/index/") + || (url.getPath().equals("/post") && url.getQuery().startsWith( + "tags=")); } }