X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=inline;f=src%2Fbe%2Fnikiroo%2Ffanfix%2Fsupported%2FFimfiction.java;h=08d1712e9f4aa2ccebb8f8e07e1bb49085340bc4;hb=edfd3577ad35ca77bc0312849c6f4ccfe3394a5f;hp=03a7cc21dc7f94643326e7baa37c35ec860f121f;hpb=2206ef66ee00ad42d806f04a7b7ad6f8cb2d8828;p=nikiroo-utils.git
diff --git a/src/be/nikiroo/fanfix/supported/Fimfiction.java b/src/be/nikiroo/fanfix/supported/Fimfiction.java
index 03a7cc2..08d1712 100644
--- a/src/be/nikiroo/fanfix/supported/Fimfiction.java
+++ b/src/be/nikiroo/fanfix/supported/Fimfiction.java
@@ -14,6 +14,7 @@ import java.util.Scanner;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Progress;
import be.nikiroo.utils.StringUtils;
/**
@@ -69,22 +70,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();
}
}
@@ -155,12 +170,12 @@ class Fimfiction extends BasicSupport {
@Override
protected String getDesc(URL source, InputStream in) {
// the og: meta version is the SHORT resume, this is the LONG resume
- return getLine(in, "class=\"more_button hidden\"", -1);
+ return getLine(in, "class=\"description-text bbcode\"", 1);
}
private BufferedImage getCover(InputStream in) {
// Note: the 'og:image' is the SMALL cover, not the full version
- String cover = getLine(in, "
", 1);
+ String cover = getLine(in, "class=\"story_container__story_image\"", 1);
if (cover != null) {
int pos = cover.indexOf('"');
if (pos >= 0) {
@@ -172,58 +187,69 @@ class Fimfiction extends BasicSupport {
}
}
- return getImage(null, cover);
+ return getImage(this, null, cover);
}
@Override
- protected List
> getChapters(URL source, InputStream in) {
+ protected List> getChapters(URL source, InputStream in,
+ Progress pg) {
List> urls = new ArrayList>();
@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("class=\"chapter_link\"")
- || line.contains("class='chapter_link'")) {
- // Chapter name
- String name = line;
- int pos = name.indexOf('>');
- if (pos >= 0) {
- name = name.substring(pos + 1);
- pos = name.indexOf('<');
+ String line = scan.next().trim();
+
+ if (!started) {
+ started = line.equals("");
+ } else {
+ if (line.equals("")) {
+ break;
+ }
+
+ if (line.startsWith("');
if (pos >= 0) {
- name = name.substring(0, pos);
+ name = name.substring(pos + 1);
+ pos = name.indexOf('<');
+ if (pos >= 0) {
+ name = name.substring(0, pos);
+ }
}
- }
- // Chapter content
- pos = line.indexOf('/');
- if (pos >= 0) {
- line = line.substring(pos); // we take the /, not +1
- pos = line.indexOf('"');
+ // Chapter content
+ pos = line.indexOf('/');
if (pos >= 0) {
- line = line.substring(0, pos);
+ line = line.substring(pos); // we take the /, not +1
+ pos = line.indexOf('"');
+ if (pos >= 0) {
+ line = line.substring(0, pos);
+ }
}
- }
- 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;
- }
+ 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 String getKey() {
+ return key;
+ }
- public URL getValue() {
- return value;
- }
- });
- } catch (MalformedURLException e) {
- Instance.syserr(e);
+ public URL getValue() {
+ return value;
+ }
+ });
+ } catch (MalformedURLException e) {
+ Instance.syserr(e);
+ }
}
}
}
@@ -232,8 +258,9 @@ class Fimfiction extends BasicSupport {
}
@Override
- protected String getChapterContent(URL source, InputStream in, int number) {
- return getLine(in, "", 1);
+ protected String getChapterContent(URL source, InputStream in, int number,
+ Progress pg) {
+ return getLine(in, "
", 1);
}
@Override