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.Progress;
import be.nikiroo.utils.StringUtils;
/**
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("");
}
private String getAuthor(InputStream in) {
+ String author = null;
+
int i = 0;
@SuppressWarnings("resource")
Scanner scan = new Scanner(in, "UTF-8");
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 fixAuthor(author);
}
private String getDate(InputStream in) {
+ "/" + url.getPath() + "/" + line;
}
- return getImage(null, line);
+ return getImage(this, null, line);
}
}
}
}
@Override
- protected List<Entry<String, URL>> getChapters(URL source, InputStream in) {
+ protected List<Entry<String, URL>> getChapters(URL source, InputStream in,
+ Progress pg) {
List<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
String base = source.toString();
String line = getLine(in, "id=chap_select", 0);
String key = "<option value=";
int i = 1;
- for (pos = line.indexOf(key); pos >= 0; pos = line.indexOf(key, pos), i++) {
- pos = line.indexOf('>', pos);
- if (pos >= 0) {
- int endOfName = line.indexOf('<', pos);
- if (endOfName >= 0) {
- String name = line.substring(pos + 1, endOfName);
- String chapNum = i + ".";
- if (name.startsWith(chapNum)) {
- name = name.substring(chapNum.length(), name.length());
- }
-
- try {
- final String chapName = name.trim();
- final URL chapURL = new URL(base + i + suffix);
- urls.add(new Entry<String, URL>() {
- public URL setValue(URL value) {
- return null;
- }
- public URL getValue() {
- return chapURL;
- }
+ if (line != null) {
+ for (pos = line.indexOf(key); pos >= 0; pos = line
+ .indexOf(key, pos), i++) {
+ pos = line.indexOf('>', pos);
+ if (pos >= 0) {
+ int endOfName = line.indexOf('<', pos);
+ if (endOfName >= 0) {
+ String name = line.substring(pos + 1, endOfName);
+ String chapNum = i + ".";
+ if (name.startsWith(chapNum)) {
+ name = name.substring(chapNum.length(),
+ name.length());
+ }
- public String getKey() {
- return chapName;
- }
- });
- } catch (MalformedURLException e) {
- Instance.syserr(new IOException("Cannot parse chapter "
- + i + " url: " + (base + i + suffix), e));
+ try {
+ final String chapName = name.trim();
+ final URL chapURL = new URL(base + i + suffix);
+ urls.add(new Entry<String, URL>() {
+ public URL setValue(URL value) {
+ return null;
+ }
+
+ public URL getValue() {
+ return chapURL;
+ }
+
+ public String getKey() {
+ return chapName;
+ }
+ });
+ } catch (MalformedURLException e) {
+ Instance.syserr(new IOException(
+ "Cannot parse chapter " + i + " url: "
+ + (base + i + suffix), e));
+ }
}
}
}
+ } else {
+ // only one chapter:
+ final String chapName = getTitle(reset(in));
+ final URL chapURL = source;
+ urls.add(new Entry<String, URL>() {
+ public URL setValue(URL value) {
+ return null;
+ }
+
+ public URL getValue() {
+ return chapURL;
+ }
+
+ public String getKey() {
+ return chapName;
+ }
+ });
}
return urls;
}
@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";
if (builder.length() == 0) {
int pos = line.indexOf("<hr");
if (pos >= 0) {
- line = line.substring(pos);
+ boolean chaptered = false;
+ for (String lang : Instance.getConfig()
+ .getString(Config.CHAPTER).split(",")) {
+ String chapterWord = Instance.getConfig()
+ .getStringX(Config.CHAPTER, lang);
+ int posChap = line.indexOf(chapterWord + " ");
+ if (posChap < pos) {
+ chaptered = true;
+ break;
+ }
+ }
+
+ if (chaptered) {
+ line = line.substring(pos);
+ }
}
}
builder.append(line);
+ builder.append(' ');
}
}