X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=8d31cb83adacf1a7fa7f80dda01a3ac380197086;hb=16a81ef7656c5c692fb831927e75edde25dd77a0;hp=ba42452ff332937dc57c459ff092202829e553ff;hpb=373da363323d3a9263aa6ebd392ca3272b23b412;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java index ba42452..8d31cb8 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -1,6 +1,5 @@ package be.nikiroo.fanfix.supported; -import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -13,7 +12,8 @@ import java.util.Scanner; 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 { @@ -102,7 +102,7 @@ class MangaFox extends BasicSupport { try { in.reset(); } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } line = getLine(in, "/artist/", 0, false); @@ -117,18 +117,18 @@ class MangaFox extends BasicSupport { if (authors.isEmpty()) { return null; - } else { - StringBuilder builder = new StringBuilder(); - for (String author : authors) { - if (builder.length() > 0) { - builder.append(", "); - } + } - builder.append(author); + StringBuilder builder = new StringBuilder(); + for (String author : authors) { + if (builder.length() > 0) { + builder.append(", "); } - return builder.toString(); + builder.append(author); } + + return builder.toString(); } private String getDate(InputStream in) { @@ -162,7 +162,7 @@ class MangaFox extends BasicSupport { return null; } - private BufferedImage getCover(InputStream in) { + private Image getCover(InputStream in) { String line = getLine(in, " property=\"og:image\"", 0); String cover = null; if (line != null) { @@ -185,7 +185,7 @@ class MangaFox extends BasicSupport { try { coverIn = openEx(cover); try { - return IOUtils.toImage(coverIn); + return new Image(coverIn); } finally { coverIn.close(); } @@ -197,7 +197,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 = "

"; @@ -240,31 +241,44 @@ 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); urls.add(new Entry() { + @Override public URL setValue(URL value) { return null; } + @Override public String getKey() { return key; } + @Override public URL getValue() { return value; } }); } catch (MalformedURLException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } } } + 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); @@ -272,19 +286,29 @@ 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); try { in.reset(); } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } String linkImageLine = getLine(in, "return enlarge()", 1); @@ -312,17 +336,18 @@ 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 { in.close(); } catch (IOException e) { - Instance.syserr(e); + Instance.getTraceHandler().error(e); } } @@ -333,10 +358,12 @@ 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: " - + linkNext, e)); + Instance.getTraceHandler().error( + new IOException( + "Cannot get the next manga page which is: " + + linkNext, e)); } }