X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FE621.java;h=dfa9e5ed6a60e4694fc8494dcf196b4328259ee6;hb=727108fef9dcc661d45fa69ebf8b76f5128a2b6f;hp=c57f8fd2cfbe0c565f15904cc5873a085acbb8b3;hpb=b56c9d60fe4ed9470881ebf6221acb0a52997291;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index c57f8fd..dfa9e5e 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -3,14 +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.Collections; import java.util.LinkedList; import java.util.List; -import java.util.AbstractMap.SimpleEntry; import java.util.Map.Entry; import java.util.Scanner; @@ -33,11 +33,6 @@ import be.nikiroo.utils.StringUtils; * @author niki */ class E621 extends BasicSupport_Deprecated { - @Override - public String getSourceName() { - return "e621.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -46,9 +41,9 @@ class E621 extends BasicSupport_Deprecated { meta.setAuthor(getAuthor(source, reset(in))); meta.setDate(""); meta.setTags(getTags(source, reset(in), false)); - meta.setSource(getSourceName()); + meta.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); meta.setLang("en"); @@ -58,8 +53,6 @@ class E621 extends BasicSupport_Deprecated { meta.setCover(getCover(source, reset(in))); meta.setFakeCover(true); - System.out.println("Meta from e621: "+meta); - return meta; } @@ -286,8 +279,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(); } @@ -296,6 +289,8 @@ class E621 extends BasicSupport_Deprecated { } } + // They are sorted in reverse order on the website + Collections.reverse(urls); return urls; } @@ -373,11 +368,42 @@ 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 = "?tags="; + if (source.toString().contains(key)) { + int pos = source.toString().indexOf(key); + String tags = source.toString().substring(pos + key.length()); + tags = tags.replace("+", "%20"); + + String base = source.toString().substring(0, pos); + if (!base.endsWith("/")) { + base += "/"; + } + if (base.endsWith("/search/")) { + base = base.substring(0, base.indexOf("/search/") + 1); + } + + try { + return new URL(base + "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/search") && url.getQuery() + .startsWith("tags=")); } }