X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;fp=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=fb72bf531d00d9e6b20d88f127b9a19e98dc64e3;hb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d;hp=0000000000000000000000000000000000000000;hpb=ed48062ebfb0d611b74834e313bfb0a2b81416e6;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java new file mode 100644 index 0000000..fb72bf5 --- /dev/null +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -0,0 +1,409 @@ +package be.nikiroo.fanfix.supported; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map.Entry; +import java.util.Scanner; + +import be.nikiroo.fanfix.Instance; +import be.nikiroo.utils.StringUtils; + +class MangaFox extends BasicSupport { + @Override + protected boolean isHtml() { + return true; + } + + @Override + public String getSourceName() { + return "MangaFox.met"; + } + + @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()); + } + } + } + + 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); + } + } + } + + return null; + } + + @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()); + } + } + } + + try { + in.reset(); + } catch (IOException e) { + Instance.syserr(e); + } + + 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()); + } + } + } + + 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(); + } + } + + @Override + protected String getDate(URL source, InputStream in) { + String line = getLine(in, "/released/", 0); + if (line != null) { + line = StringUtils.unhtml(line); + return line.trim(); + } + + return null; + } + + @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); + } + } + } + + 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); + } + } + } + + if (cover != null) { + try { + return new URL(cover); + } catch (MalformedURLException e) { + Instance.syserr(e); + } + } + + return null; + } + + @Override + protected List> getChapters(URL source, InputStream in) { + List> urls = new ArrayList>(); + + String volumeAt = "

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