X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFanfiction.java;h=0dcd7903e077d2bb6afa268247e04ea39a04722a;hp=e84acaa2c78368caaf6dd6d575d2a0bfce7b5112;hb=8d59ce0748baeeea0458bab49716ab4543aae439;hpb=a4143cd74a90e17a811a4581cbeb213fed1f6304 diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index e84acaa..0dcd790 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; @@ -15,6 +15,8 @@ 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; /** @@ -24,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(); @@ -43,12 +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.setSource(getType().getSourceName()); meta.setUrl(source.toString()); - meta.setPublisher(getSourceName()); + 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); @@ -73,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\""; @@ -121,7 +118,7 @@ class Fanfiction extends BasicSupport { } } - return null; + return ""; } private String getAuthor(InputStream in) { @@ -141,7 +138,7 @@ class Fanfiction extends BasicSupport { } } - return fixAuthor(author); + return bsHelper.fixAuthor(author); } private String getDate(InputStream in) { @@ -160,8 +157,10 @@ class Fanfiction extends BasicSupport { return sdf .format(new Date(1000 * Long.parseLong(line))); } catch (NumberFormatException e) { - Instance.syserr(new IOException( - "Cannot convert publication date: " + line, e)); + Instance.getTraceHandler().error( + new IOException( + "Cannot convert publication date: " + + line, e)); } } } @@ -175,7 +174,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) { @@ -210,7 +209,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(); @@ -240,25 +240,14 @@ class Fanfiction extends BasicSupport { } try { - final String chapName = name.trim(); - final URL chapURL = new URL(base + i + suffix); - urls.add(new Entry() { - public URL setValue(URL value) { - return null; - } - - public URL getValue() { - return chapURL; - } - - public String getKey() { - return chapName; - } - }); + urls.add(new AbstractMap.SimpleEntry( + name.trim(), new URL(base + i + suffix))); } catch (MalformedURLException e) { - Instance.syserr(new IOException( - "Cannot parse chapter " + i + " url: " - + (base + i + suffix), e)); + Instance.getTraceHandler() + .error(new IOException( + "Cannot parse chapter " + i + + " url: " + + (base + i + suffix), e)); } } } @@ -268,14 +257,17 @@ class Fanfiction extends BasicSupport { final String chapName = getTitle(reset(in)); final URL chapURL = source; urls.add(new Entry() { + @Override public URL setValue(URL value) { return null; } + @Override public URL getValue() { return chapURL; } + @Override public String getKey() { return chapName; } @@ -286,7 +278,8 @@ class Fanfiction extends BasicSupport { } @Override - protected String getChapterContent(URL source, InputStream in, int number) { + protected String getChapterContent(URL source, InputStream in, int number, + Progress pg) { StringBuilder builder = new StringBuilder(); String startAt = "class='storytext "; String endAt1 = "function review_init"; @@ -311,10 +304,10 @@ class Fanfiction extends BasicSupport { int pos = line.indexOf("= 0) { boolean chaptered = false; - for (String lang : Instance.getConfig() - .getString(Config.CHAPTER).split(",")) { + for (String lang : Instance.getConfig().getList( + Config.CONF_CHAPTER)) { String chapterWord = Instance.getConfig() - .getStringX(Config.CHAPTER, lang); + .getStringX(Config.CONF_CHAPTER, lang); int posChap = line.indexOf(chapterWord + " "); if (posChap < pos) { chaptered = true; @@ -329,7 +322,7 @@ class Fanfiction extends BasicSupport { } builder.append(line); - builder.append('\n'); + builder.append(' '); } }