X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=5dee0d6a9f95cd2bf4e420dbf9cec38bca3322fa;hb=727108fef9dcc661d45fa69ebf8b76f5128a2b6f;hp=2c4c2f3063f2cbcc6daa0ad7f0ae9fb9cbfeca35;hpb=d3c15421430e85e3afeefef211b4f791753e17ba;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java index 2c4c2f3..5dee0d6 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -4,13 +4,22 @@ 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 java.util.SortedMap; +import java.util.TreeMap; + +import org.jsoup.helper.DataUtil; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; class MangaFox extends BasicSupport { @@ -20,162 +29,104 @@ class MangaFox extends BasicSupport { } @Override - public String getSourceName() { - return "MangaFox.me"; - } - - @Override - protected String getSubject(URL source, InputStream in) { - return "manga"; - } - - @Override - public boolean isImageDocument(URL source, InputStream in) - throws IOException { - return true; - } - - @Override - protected List getTags(URL source, InputStream in) { - List tags = new ArrayList(); - - 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()); - } - } + protected MetaData getMeta() throws IOException { + MetaData meta = new MetaData(); + Element doc = getSourceNode(); + + Element title = doc.getElementById("title"); + Elements table = null; + if (title != null) { + table = title.getElementsByTag("table"); } - - return tags; - } - - @Override - protected String getTitle(URL source, 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); + if (table != null) { + // Rows: header, data + Elements rows = table.first().getElementsByTag("tr"); + if (rows.size() > 1) { + table = rows.get(1).getElementsByTag("td"); + // Columns: Realeased, Authors, Artists, Genres + if (table.size() < 4) { + table = null; } } } - return null; - } + meta.setTitle(getTitle()); + if (table != null) { + meta.setAuthor(getAuthors(table.get(1).text() + "," + + table.get(2).text())); - @Override - protected String getAuthor(URL source, 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()); - } - } + meta.setDate(StringUtils.unhtml(table.get(0).text()).trim()); + meta.setTags(explode(table.get(3).text())); } + meta.setSource(getType().getSourceName()); + meta.setUrl(getSource().toString()); + meta.setPublisher(getType().getSourceName()); + meta.setUuid(getSource().toString()); + meta.setLuid(""); + meta.setLang("en"); + meta.setSubject("manga"); + meta.setType(getType().toString()); + meta.setImageDocument(true); + meta.setCover(getCover()); + + return meta; + } - try { - in.reset(); - } catch (IOException e) { - Instance.syserr(e); - } + private String getTitle() { + Element doc = getSourceNode(); - 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()); - } - } + Element title = doc.getElementById("title"); + Element h1 = title.getElementsByTag("h1").first(); + if (h1 != null) { + return StringUtils.unhtml(h1.text()).trim(); } - if (authors.isEmpty()) { - return null; - } else { - StringBuilder builder = new StringBuilder(); - for (String author : authors) { - if (builder.length() > 0) { - builder.append(", "); - } - - builder.append(author); - } - - return builder.toString(); - } + return null; } - @Override - protected String getDate(URL source, InputStream in) { - String line = getLine(in, "/released/", 0); - if (line != null) { - line = StringUtils.unhtml(line); - return line.trim(); + private String getAuthors(String authorList) { + String author = ""; + for (String auth : explode(authorList)) { + if (!author.isEmpty()) { + author = author + ", "; + } + author += auth; } - return null; + return author; } @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("summary").first(); + if (title != null) { + return StringUtils.unhtml(title.text()).trim(); } return null; } - @Override - protected URL getCover(URL url, 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("cover").first(); + if (cover != null) { + cover = cover.getElementsByTag("img").first(); } if (cover != null) { + String coverUrl = cover.absUrl("src"); + + InputStream coverIn; try { - return new URL(cover); - } catch (MalformedURLException e) { - Instance.syserr(e); + coverIn = openEx(coverUrl); + try { + return new Image(coverIn); + } finally { + coverIn.close(); + } + } catch (IOException e) { + Instance.getTraceHandler().error(e); } } @@ -183,162 +134,176 @@ 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 = "