X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FE621.java;h=2b7e54d862f242c5cad72fdd8a3b58aee7a6e80f;hb=86d83218623fe9b297f1f03e0fc247dc2ede95b0;hp=527e0928cc33cb51215d30ca505dcd6dd4174e8d;hpb=ed08c17162aa8cbdb0cbe6a6045815b987236b9f;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index 527e092..2b7e54d 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -1,24 +1,34 @@ package be.nikiroo.fanfix.supported; -import java.awt.image.BufferedImage; 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.util.AbstractMap; import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedList; import java.util.List; import java.util.Map.Entry; -import java.util.Scanner; + +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.Chapter; import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.fanfix.data.Story; +import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; /** - * Support class for e621.net and e926.net, a Furry website supporting comics, + * Support class for e621.net and + * e926.net, a Furry website supporting comics, * including some of MLP. *
* e926.net only shows the "clean" images and
@@ -28,253 +38,311 @@ import be.nikiroo.utils.StringUtils;
*/
class E621 extends BasicSupport {
@Override
- public String getSourceName() {
- return "e621.net";
+ protected boolean supports(URL url) {
+ String host = url.getHost();
+ if (host.startsWith("www.")) {
+ host = host.substring("www.".length());
+ }
+
+ return ("e621.net".equals(host) || "e926.net".equals(host)) && (isPool(url) || isSearchOrSet(url));
+ }
+
+ @Override
+ protected boolean isHtml() {
+ return true;
}
@Override
- protected MetaData getMeta(URL source, InputStream in) throws IOException {
+ protected MetaData getMeta() throws IOException {
MetaData meta = new MetaData();
- meta.setTitle(getTitle(reset(in)));
- meta.setAuthor(getAuthor(source, reset(in)));
+ meta.setTitle(getTitle());
+ meta.setAuthor(getAuthor());
meta.setDate("");
- meta.setTags(new ArrayList
");
- if (pos >= 0) {
- images = images.substring(1, pos - 1);
- return getImage(this, null, images);
- }
+ if (source.getHost().contains("e926")) {
+ baseUrl = baseUrl.replace("e621", "e926");
}
- return null;
- }
-
- private String getAuthor(URL source, InputStream in) throws IOException {
- String author = getLine(in, "href=\"/post/show/", 0);
- if (author != null) {
- String key = "href=\"";
- int pos = author.indexOf(key);
- if (pos >= 0) {
- author = author.substring(pos + key.length());
- pos = author.indexOf("\"");
- if (pos >= 0) {
- author = author.substring(0, pos - 1);
- String page = source.getProtocol() + "://"
- + source.getHost() + author;
- try {
- InputStream pageIn = Instance.getCache().open(
- new URL(page), this, false);
- try {
- key = "class=\"tag-type-artist\"";
- author = getLine(pageIn, key, 0);
- if (author != null) {
- pos = author.indexOf("= 0) {
- author = author.substring(pos);
- pos = author.indexOf("");
- if (pos >= 0) {
- author = author.substring(0, pos);
- return StringUtils.unhtml(author);
- }
- }
- }
- } finally {
- pageIn.close();
- }
- } catch (Exception e) {
- // No author found
+ for (int i = 1; true; i++) {
+ URL url = new URL(baseUrl + i + parameters);
+ try {
+ InputStream pageI = Instance.getInstance().getCache().open(url, this, false);
+ try {
+ if (IOUtils.readSmallStream(pageI).contains("Nobody here but us chickens!")) {
+ break;
}
+ urls.add(new AbstractMap.SimpleEntry
");
+ }
+
+ return builder.toString();
+ }
+
+ @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 + "/posts/" + poolNumber);
+ } catch (NumberFormatException e) {
+ // Not a simple ppol, skip
+ } catch (MalformedURLException e) {
+ // Cannot happen
}
-
- if (title.startsWith("Pool:")) {
- title = title.substring("Pool:".length());
+ }
+
+ if (isSetOriginalUrl(source)) {
+ try {
+ 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())
+ return new URL(el.absUrl("href"));
+ }
+ }
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);
}
+ }
- title = StringUtils.unhtml(title).trim();
+ if (isPool(source)) {
+ try {
+ return new URL(source.toString().replace("/pool/show/", "/pools/"));
+ } catch (MalformedURLException e) {
+ }
}
- return title;
+ return super.getCanonicalUrl(source);
}
- @Override
- protected String getDesc(URL source, InputStream in) throws IOException {
- String desc = getLine(in, "margin-bottom: 2em;", 0);
+ // returns "xxx+ddd+ggg" if "tags=xxx+ddd+ggg" was present in the query
+ private String getTagsFromUrl(URL url) {
+ String tags = url == null ? "" : url.getQuery();
+ int pos = tags.indexOf("tags=");
- if (desc != null) {
- StringBuilder builder = new StringBuilder();
+ if (pos >= 0) {
+ tags = tags.substring(pos).substring("tags=".length());
+ } else {
+ return "";
+ }
- boolean inTags = false;
- for (char car : desc.toCharArray()) {
- if ((inTags && car == '>') || (!inTags && car == '<')) {
- inTags = !inTags;
- }
+ pos = tags.indexOf('&');
+ if (pos > 0) {
+ tags = tags.substring(0, pos);
+ }
+ pos = tags.indexOf('/');
+ if (pos > 0) {
+ tags = tags.substring(0, pos);
+ }
- if (inTags) {
- builder.append(car);
- }
+ return tags;
+ }
+
+ private String getTitle() {
+ String title = "";
+
+ Element el = getSourceNode().getElementsByTag("title").first();
+ if (el != null) {
+ title = el.text().trim();
+ }
+
+ for (String s : new String[] { "e621", "-", "e621" }) {
+ if (title.startsWith(s)) {
+ title = title.substring(s.length()).trim();
+ }
+ if (title.endsWith(s)) {
+ title = title.substring(0, title.length() - s.length()).trim();
}
- return builder.toString().trim();
}
- return null;
+ if (isSearchOrSet(getSource())) {
+ title = title.isEmpty() ? "e621" : "[e621] " + title;
+ }
+ return title;
}
- @Override
- protected List
");
- }
- }
- }
+ return tags;
+ }
+
+ private Image getCover() throws IOException {
+ Image image = null;
+ List