X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFanfiction.java;h=282192e065bb82fd238c06b863d0e9a3647f4917;hb=d66deb8d8b30cff6b54db352eef34a3508939f84;hp=9be098d6b8bd67e5a419a10acd8fedc52ee5d695;hpb=68686a37a591a767f6d1af428ea0d5f3d3a1ddc1;p=nikiroo-utils.git diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index 9be098d..282192e 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,11 +40,12 @@ class Fanfiction extends BasicSupport { meta.setAuthor(getAuthor(reset(in))); meta.setDate(getDate(reset(in))); meta.setTags(getTags(reset(in))); - meta.setSource(getSourceName()); - meta.setPublisher(getSourceName()); + meta.setSource(getType().getSourceName()); + meta.setUrl(source.toString()); + meta.setPublisher(getType().getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); - meta.setLang("EN"); + meta.setLang("en"); // TODO! meta.setSubject(getSubject(reset(in))); meta.setType(getType().toString()); meta.setImageDocument(false); @@ -71,7 +70,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\""; @@ -119,10 +118,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"); @@ -131,12 +132,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) { @@ -151,12 +153,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)); } } } @@ -170,7 +172,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) { @@ -195,7 +197,7 @@ class Fanfiction extends BasicSupport { + "/" + url.getPath() + "/" + line; } - return getImage(null, line); + return getImage(this, null, line); } } } @@ -205,7 +207,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(); @@ -219,46 +222,59 @@ class Fanfiction extends BasicSupport { String line = getLine(in, "id=chap_select", 0); String key = "