X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFanfiction.java;h=060705cadd09ea0867c1152245a0bd90697fac6f;hb=cfdaf6052ddc5ca44cf19f1f6d9f154cc8443024;hp=cbbc0851621d56f04288fe4539ed4019651c1fd8;hpb=08fe2e33007063e30fe22dc1d290f8afaa18eb1d;p=fanfix.git diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index cbbc085..060705c 100644 --- a/src/be/nikiroo/fanfix/supported/Fanfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fanfiction.java @@ -5,6 +5,7 @@ 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; @@ -12,6 +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; /** @@ -21,19 +26,32 @@ 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"; + protected MetaData getMeta(URL source, InputStream in) throws IOException { + MetaData meta = new MetaData(); + + meta.setTitle(getTitle(reset(in))); + meta.setAuthor(getAuthor(reset(in))); + meta.setDate(getDate(reset(in))); + meta.setTags(getTags(reset(in))); + meta.setUrl(source.toString()); + meta.setUuid(source.toString()); + meta.setLuid(""); + meta.setLang("en"); // TODO find language of book + meta.setSubject(getSubject(reset(in))); + meta.setImageDocument(false); + meta.setCover(getCover(source, reset(in))); + + return meta; } - @Override - protected String getSubject(URL source, InputStream in) { + private String getSubject(InputStream in) { String line = getLine(in, "id=pre_story_links", 0); if (line != null) { int pos = line.lastIndexOf('"'); @@ -41,7 +59,7 @@ class Fanfiction extends BasicSupport { line = line.substring(pos + 1); pos = line.indexOf('<'); if (pos >= 0) { - return line.substring(0, pos); + return StringUtils.unhtml(line.substring(0, pos)).trim(); } } } @@ -49,10 +67,8 @@ class Fanfiction extends BasicSupport { return null; } - @Override - protected List getTags(URL source, InputStream in) - throws IOException { - List tags = super.getTags(source, in); + private List getTags(InputStream in) { + List tags = new ArrayList(); String key = "title=\"Send Private Message\""; String line = getLine(in, key, 2); @@ -71,7 +87,7 @@ class Fanfiction extends BasicSupport { } for (String tag : line.split("-")) { - tags.add(tag.trim()); + tags.add(StringUtils.unhtml(tag).trim()); } } } @@ -80,8 +96,7 @@ class Fanfiction extends BasicSupport { return tags; } - @Override - protected String getTitle(URL source, InputStream in) { + private String getTitle(InputStream in) { int i = 0; @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); @@ -95,16 +110,17 @@ class Fanfiction extends BasicSupport { line = line.substring("Follow/Fav".length()).trim(); } - return line; + return StringUtils.unhtml(line).trim(); } } } - return null; + return ""; } - @Override - protected String getAuthor(URL source, InputStream in) { + private String getAuthor(InputStream in) { + String author = null; + int i = 0; @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); @@ -113,16 +129,16 @@ 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); } - @Override - protected String getDate(URL source, InputStream in) { + private String getDate(InputStream in) { String key = "Published: > getChapters(URL source, InputStream in) { + protected List> getChapters(URL source, InputStream in, + Progress pg) { List> urls = new ArrayList>(); String base = source.toString(); @@ -207,46 +219,59 @@ class Fanfiction extends BasicSupport { String line = getLine(in, "id=chap_select", 0); String key = "