X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FMangaFox.java;h=d6f146429bf19a4c67d4b7305c89a9c96f8d7229;hb=211f7ddb50f68aa8a999023ef6d63d5756bdace6;hp=d86cc738c2f731707e98bb328e93f4f2005a134e;hpb=406447a4c017f2a4592429a67d546a6984460617;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/MangaFox.java b/src/be/nikiroo/fanfix/supported/MangaFox.java index d86cc73..d6f1464 100644 --- a/src/be/nikiroo/fanfix/supported/MangaFox.java +++ b/src/be/nikiroo/fanfix/supported/MangaFox.java @@ -13,7 +13,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.ImageUtils; +import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; class MangaFox extends BasicSupport { @@ -117,18 +118,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) { @@ -185,7 +186,7 @@ class MangaFox extends BasicSupport { try { coverIn = openEx(cover); try { - return IOUtils.toImage(coverIn); + return ImageUtils.fromStream(coverIn); } finally { coverIn.close(); } @@ -197,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 = "

"; @@ -240,21 +242,21 @@ 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; } @@ -265,6 +267,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); @@ -272,12 +287,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); @@ -317,6 +342,7 @@ class MangaFox extends BasicSupport { // to help with the retry and the originalUrl, part 2 refresh(linkImage); + pg.setProgress((i++) % pg.getMax()); if (close) { try { @@ -333,6 +359,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: "