X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=c8eaa1d3035d0fabee3af3ccd2a797ec080a7cce;hb=326093dc53fa48019c94f59bd006b307d755b392;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..c8eaa1d 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -1,5 +1,6 @@ package be.nikiroo.fanfix.supported; +import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -11,6 +12,9 @@ import java.util.Map.Entry; import java.util.Scanner; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.utils.ImageUtils; +import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; class MangaFox extends BasicSupport { @@ -25,18 +29,28 @@ class MangaFox extends BasicSupport { } @Override - protected String getSubject(URL source, InputStream in) { - return "manga"; + protected MetaData getMeta(URL source, InputStream in) 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.setLuid(""); + meta.setLang("EN"); + meta.setSubject("manga"); + meta.setType(getType().toString()); + meta.setImageDocument(true); + meta.setCover(getCover(reset(in))); + + return meta; } - @Override - public boolean isImageDocument(URL source, InputStream in) - throws IOException { - return true; - } - - @Override - protected List getTags(URL source, InputStream in) { + private List getTags(InputStream in) { List tags = new ArrayList(); String line = getLine(in, "/genres/", 0); @@ -53,8 +67,7 @@ class MangaFox extends BasicSupport { return tags; } - @Override - protected String getTitle(URL source, InputStream in) { + private String getTitle(InputStream in) { String line = getLine(in, " property=\"og:title\"", 0); if (line != null) { int pos = -1; @@ -74,8 +87,7 @@ class MangaFox extends BasicSupport { return null; } - @Override - protected String getAuthor(URL source, InputStream in) { + private String getAuthor(InputStream in) { List authors = new ArrayList(); String line = getLine(in, "/author/", 0, false); @@ -120,8 +132,7 @@ class MangaFox extends BasicSupport { } } - @Override - protected String getDate(URL source, InputStream in) { + private String getDate(InputStream in) { String line = getLine(in, "/released/", 0); if (line != null) { line = StringUtils.unhtml(line); @@ -152,8 +163,7 @@ class MangaFox extends BasicSupport { return null; } - @Override - protected URL getCover(URL url, InputStream in) { + private BufferedImage getCover(InputStream in) { String line = getLine(in, " property=\"og:image\"", 0); String cover = null; if (line != null) { @@ -172,10 +182,15 @@ class MangaFox extends BasicSupport { } if (cover != null) { + InputStream coverIn; try { - return new URL(cover); - } catch (MalformedURLException e) { - Instance.syserr(e); + coverIn = openEx(cover); + try { + return ImageUtils.fromStream(coverIn); + } finally { + coverIn.close(); + } + } catch (IOException e) { } } @@ -183,7 +198,8 @@ class MangaFox extends BasicSupport { } @Override - protected List> getChapters(URL source, InputStream in) { + protected List> getChapters(URL source, InputStream in, + Progress pg) { List> urls = new ArrayList>(); String volumeAt = "

"; @@ -226,9 +242,6 @@ class MangaFox extends BasicSupport { } } - // to help with the retry and the originalUrl - refresh(url); - try { final String key = name; final URL value = new URL(url); @@ -251,6 +264,19 @@ class MangaFox extends BasicSupport { } } + if (pg == null) { + pg = new Progress(0, urls.size()); + } else { + pg.setMinMax(0, urls.size()); + } + + int i = 1; + for (Entry entry : urls) { + // to help with the retry and the originalUrl + refresh(entry.getValue().toString()); + pg.setProgress(i++); + } + // the chapters are in reversed order Collections.reverse(urls); @@ -258,12 +284,22 @@ class MangaFox extends BasicSupport { } @Override - protected String getChapterContent(URL source, InputStream in, int number) { + protected String getChapterContent(URL source, InputStream in, int number, + Progress pg) { + if (pg == null) { + pg = new Progress(); + } else { + // Since we have no idea how many images we have, we cycle from 0 + // to max, then again, then again... + pg.setMinMax(0, 20); + } + StringBuilder builder = new StringBuilder(); String base = getCurrentReferer().toString(); int pos = base.lastIndexOf('/'); base = base.substring(0, pos + 1); // including the '/' at the end + int i = 1; boolean close = false; while (in != null) { String linkNextLine = getLine(in, "return enlarge()", 0); @@ -298,11 +334,12 @@ class MangaFox extends BasicSupport { builder.append("["); // to help with the retry and the originalUrl, part 1 builder.append(withoutQuery(linkImage)); - builder.append("]\n"); + builder.append("]
"); } // to help with the retry and the originalUrl, part 2 refresh(linkImage); + pg.setProgress((i++) % pg.getMax()); if (close) { try { @@ -319,6 +356,7 @@ class MangaFox extends BasicSupport { url = new URL(base + linkNext); in = openEx(base + linkNext); setCurrentReferer(url); + pg.setProgress((i++) % pg.getMax()); } catch (IOException e) { Instance.syserr(new IOException( "Cannot get the next manga page which is: "