X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFanfiction.java;h=060705cadd09ea0867c1152245a0bd90697fac6f;hb=cfdaf6052ddc5ca44cf19f1f6d9f154cc8443024;hp=2cbe696052dc16ec61e3ba333ac50c8180486aaf;hpb=2206ef66ee00ad42d806f04a7b7ad6f8cb2d8828;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index 2cbe696..060705c 100644 --- a/src/be/nikiroo/fanfix/supported/Fanfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fanfiction.java @@ -1,11 +1,11 @@ package be.nikiroo.fanfix.supported; -import java.awt.image.BufferedImage; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.text.SimpleDateFormat; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -13,7 +13,10 @@ import java.util.Map.Entry; import java.util.Scanner; import be.nikiroo.fanfix.Instance; +import be.nikiroo.fanfix.bundles.Config; import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.utils.Image; +import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; /** @@ -23,17 +26,12 @@ import be.nikiroo.utils.StringUtils; * * @author niki */ -class Fanfiction extends BasicSupport { +class Fanfiction extends BasicSupport_Deprecated { @Override protected boolean isHtml() { return true; } - @Override - public String getSourceName() { - return "Fanfiction.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -42,14 +40,11 @@ class Fanfiction extends BasicSupport { 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.setLang("en"); // TODO find language of book meta.setSubject(getSubject(reset(in))); - meta.setType(getType().toString()); meta.setImageDocument(false); meta.setCover(getCover(source, reset(in))); @@ -72,7 +67,7 @@ class Fanfiction extends BasicSupport { return null; } - private List getTags(InputStream in) throws IOException { + private List getTags(InputStream in) { List tags = new ArrayList(); String key = "title=\"Send Private Message\""; @@ -120,10 +115,12 @@ class Fanfiction extends BasicSupport { } } - return null; + return ""; } private String getAuthor(InputStream in) { + String author = null; + int i = 0; @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); @@ -132,12 +129,13 @@ class Fanfiction extends BasicSupport { String line = scan.next(); if (line.contains("xcontrast_txt")) { if ((++i) == 3) { - return StringUtils.unhtml(line).trim(); + author = StringUtils.unhtml(line).trim(); + break; } } } - return null; + return bsHelper.fixAuthor(author); } private String getDate(InputStream in) { @@ -152,12 +150,12 @@ class Fanfiction extends BasicSupport { line = line.substring(0, pos).trim(); try { SimpleDateFormat sdf = new SimpleDateFormat( - "YYYY-MM-dd"); + "yyyy-MM-dd"); return sdf .format(new Date(1000 * Long.parseLong(line))); } catch (NumberFormatException e) { - Instance.syserr(new IOException( - "Cannot convert publication date: " + line, e)); + Instance.getInstance().getTraceHandler() + .error(new IOException("Cannot convert publication date: " + line, e)); } } } @@ -171,7 +169,7 @@ class Fanfiction extends BasicSupport { return getLine(in, "title=\"Send Private Message\"", 1); } - private BufferedImage getCover(URL url, InputStream in) { + private Image getCover(URL url, InputStream in) { String key = "class='cimage"; String line = getLine(in, key, 0); if (line != null) { @@ -196,7 +194,7 @@ class Fanfiction extends BasicSupport { + "/" + url.getPath() + "/" + line; } - return getImage(null, line); + return getImage(this, null, line); } } } @@ -206,7 +204,8 @@ class Fanfiction extends BasicSupport { } @Override - protected List> getChapters(URL source, InputStream in) { + protected List> getChapters(URL source, InputStream in, + Progress pg) { List> urls = new ArrayList>(); String base = source.toString(); @@ -220,46 +219,59 @@ class Fanfiction extends BasicSupport { String line = getLine(in, "id=chap_select", 0); String key = "