X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=a9db419e803eae8cb5125e63d1af346a00978205;hb=f3ce1b69a14003f0a6067e501b36a9051bceb34a;hp=ba42452ff332937dc57c459ff092202829e553ff;hpb=373da363323d3a9263aa6ebd392ca3272b23b412;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java index ba42452..a9db419 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -1,19 +1,23 @@ package be.nikiroo.fanfix.supported; -import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Collections; 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 be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; -import be.nikiroo.utils.IOUtils; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; class MangaFox extends BasicSupport { @@ -23,173 +27,95 @@ class MangaFox extends BasicSupport { } @Override - public String getSourceName() { - return "MangaFox.me"; - } - - @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(reset(in))); - meta.setDate(getDate(reset(in))); - meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); - meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); - meta.setUuid(source.toString()); + meta.setTitle(getTitle()); + // No date anymore on mangafox + // meta.setDate(); + meta.setAuthor(getAuthor()); + meta.setTags(getTags()); + meta.setSource(getType().getSourceName()); + meta.setUrl(getSource().toString()); + meta.setPublisher(getType().getSourceName()); + meta.setUuid(getSource().toString()); meta.setLuid(""); - meta.setLang("EN"); + meta.setLang("en"); meta.setSubject("manga"); meta.setType(getType().toString()); meta.setImageDocument(true); - meta.setCover(getCover(reset(in))); + meta.setCover(getCover()); return meta; } - private List getTags(InputStream in) { - List tags = new ArrayList(); + private String getTitle() { + Element doc = getSourceNode(); - String line = getLine(in, "/genres/", 0); - if (line != null) { - line = StringUtils.unhtml(line); - String[] tab = line.split(","); - if (tab != null) { - for (String tag : tab) { - tags.add(tag.trim()); - } - } - } - - return tags; - } - - private String getTitle(InputStream in) { - String line = getLine(in, " property=\"og:title\"", 0); - if (line != null) { - int pos = -1; - for (int i = 0; i < 3; i++) { - pos = line.indexOf('"', pos + 1); - } - - if (pos >= 0) { - line = line.substring(pos + 1); - pos = line.indexOf('"'); - if (pos >= 0) { - return line.substring(0, pos); - } - } + Element el = doc.getElementsByClass("detail-info-right-title-font").first(); + if (el != null) { + return StringUtils.unhtml(el.text()).trim(); } return null; } - private String getAuthor(InputStream in) { - List authors = new ArrayList(); - - String line = getLine(in, "/author/", 0, false); - if (line != null) { - for (String ln : StringUtils.unhtml(line).split(",")) { - if (ln != null && !ln.trim().isEmpty() - && !authors.contains(ln.trim())) { - authors.add(ln.trim()); - } - } + private String getAuthor() { + StringBuilder builder = new StringBuilder(); + for (String author : getListA("detail-info-right-say")) { + if (builder.length() > 0) + builder.append(", "); + builder.append(author); } - try { - in.reset(); - } catch (IOException e) { - Instance.syserr(e); - } + return builder.toString(); + } - line = getLine(in, "/artist/", 0, false); - if (line != null) { - for (String ln : StringUtils.unhtml(line).split(",")) { - if (ln != null && !ln.trim().isEmpty() - && !authors.contains(ln.trim())) { - authors.add(ln.trim()); - } - } - } + private List getTags() { + return getListA("detail-info-right-tag-list"); + } - if (authors.isEmpty()) { - return null; - } else { - StringBuilder builder = new StringBuilder(); - for (String author : authors) { - if (builder.length() > 0) { - builder.append(", "); - } + private List getListA(String uniqueClass) { + List list = new ArrayList(); - builder.append(author); + Element doc = getSourceNode(); + Element el = doc.getElementsByClass(uniqueClass).first(); + if (el != null) { + for (Element valueA : el.getElementsByTag("a")) { + list.add(StringUtils.unhtml(valueA.text()).trim()); } - - return builder.toString(); - } - } - - private String getDate(InputStream in) { - String line = getLine(in, "/released/", 0); - if (line != null) { - line = StringUtils.unhtml(line); - return line.trim(); } - return null; + return list; } @Override - protected String getDesc(URL source, InputStream in) { - String line = getLine(in, " property=\"og:description\"", 0); - if (line != null) { - int pos = -1; - for (int i = 0; i < 3; i++) { - pos = line.indexOf('"', pos + 1); - } - - if (pos >= 0) { - line = line.substring(pos + 1); - pos = line.indexOf('"'); - if (pos >= 0) { - return line.substring(0, pos); - } - } + protected String getDesc() { + Element doc = getSourceNode(); + Element title = doc.getElementsByClass("fullcontent").first(); + if (title != null) { + return StringUtils.unhtml(title.text()).trim(); } return null; } - private BufferedImage getCover(InputStream in) { - String line = getLine(in, " property=\"og:image\"", 0); - String cover = null; - if (line != null) { - int pos = -1; - for (int i = 0; i < 3; i++) { - pos = line.indexOf('"', pos + 1); - } - - if (pos >= 0) { - line = line.substring(pos + 1); - pos = line.indexOf('"'); - if (pos >= 0) { - cover = line.substring(0, pos); - } - } - } - + private Image getCover() { + Element doc = getSourceNode(); + Element cover = doc.getElementsByClass("detail-info-cover-img").first(); if (cover != null) { + String coverUrl = cover.absUrl("src"); + InputStream coverIn; try { - coverIn = openEx(cover); + coverIn = openEx(coverUrl); try { - return IOUtils.toImage(coverIn); + return new Image(coverIn); } finally { coverIn.close(); } } catch (IOException e) { + Instance.getTraceHandler().error(e); } } @@ -197,196 +123,147 @@ class MangaFox extends BasicSupport { } @Override - protected List> getChapters(URL source, InputStream in) { + protected List> getChapters(Progress pg) { List> urls = new ArrayList>(); - String volumeAt = "

"; - String linkAt = "href=\"http://mangafox.me/"; - String endAt = "