X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfiction.java;h=b5df2618ce671ddaf04d7f5b644c3110c721339b;hp=1faf615207154501361164721d7be8a2178855a9;hb=cfdaf6052ddc5ca44cf19f1f6d9f154cc8443024;hpb=83f66cbbd12246a5e2f1aeee1afe36503b901814 diff --git a/src/be/nikiroo/fanfix/supported/Fimfiction.java b/src/be/nikiroo/fanfix/supported/Fimfiction.java index 1faf615..b5df261 100644 --- a/src/be/nikiroo/fanfix/supported/Fimfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fimfiction.java @@ -1,10 +1,10 @@ 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.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -14,6 +14,7 @@ import java.util.Scanner; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.data.MetaData; +import be.nikiroo.utils.Image; import be.nikiroo.utils.Progress; import be.nikiroo.utils.StringUtils; @@ -23,17 +24,12 @@ import be.nikiroo.utils.StringUtils; * * @author niki */ -class Fimfiction extends BasicSupport { +class Fimfiction extends BasicSupport_Deprecated { @Override protected boolean isHtml() { return true; } - @Override - public String getSourceName() { - return "FimFiction.net"; - } - @Override protected MetaData getMeta(URL source, InputStream in) throws IOException { MetaData meta = new MetaData(); @@ -42,14 +38,11 @@ class Fimfiction 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"); meta.setSubject("MLP"); - meta.setType(getType().toString()); meta.setImageDocument(false); meta.setCover(getCover(reset(in))); @@ -70,22 +63,36 @@ class Fimfiction extends BasicSupport { @SuppressWarnings("resource") Scanner scan = new Scanner(in, "UTF-8"); scan.useDelimiter("\\n"); + boolean started = false; while (scan.hasNext()) { String line = scan.next(); - if (line.contains("story_category") && !line.contains("title=")) { - int pos = line.indexOf('>'); - if (pos >= 0) { - line = line.substring(pos + 1); - pos = line.indexOf('<'); - if (pos >= 0) { - line = line.substring(0, pos); - } + + if (!started) { + started = line.contains("\"story_container\""); + } + + if (started && line.contains("class=\"tag-")) { + if (line.contains("index.php")) { + break; // end of *this story* tags } - line = line.trim(); - if (!tags.contains(line)) { - tags.add(line); + String keyword = "title=\""; + Scanner tagScanner = new Scanner(line); + tagScanner.useDelimiter(keyword); + if (tagScanner.hasNext()) { + tagScanner.next();// Ignore first one + } + while (tagScanner.hasNext()) { + String tag = tagScanner.next(); + if (tag.contains("\"")) { + tag = tag.split("\"")[0]; + tag = StringUtils.unhtml(tag).trim(); + if (!tag.isEmpty() && !tags.contains(tag)) { + tags.add(tag); + } + } } + tagScanner.close(); } } @@ -159,7 +166,7 @@ class Fimfiction extends BasicSupport { return getLine(in, "class=\"description-text bbcode\"", 1); } - private BufferedImage getCover(InputStream in) { + private Image getCover(InputStream in) { // Note: the 'og:image' is the SMALL cover, not the full version String cover = getLine(in, "class=\"story_container__story_image\"", 1); if (cover != null) { @@ -194,7 +201,8 @@ class Fimfiction extends BasicSupport { break; } - if (line.startsWith("'); @@ -216,24 +224,10 @@ class Fimfiction extends BasicSupport { } try { - final String key = name; - final URL value = new URL("http://www.fimfiction.net" - + line); - urls.add(new Entry() { - public URL setValue(URL value) { - return null; - } - - public String getKey() { - return key; - } - - public URL getValue() { - return value; - } - }); + urls.add(new AbstractMap.SimpleEntry(name, + new URL("http://www.fimfiction.net" + line))); } catch (MalformedURLException e) { - Instance.syserr(e); + Instance.getInstance().getTraceHandler().error(e); } } }