import org.jsoup.helper.DataUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.MetaData;
@Override
protected List<Entry<String, URL>> getChapters(Progress pg) throws IOException {
+ List<Entry<String, URL>> chapters = new LinkedList<Entry<String, URL>>();
+
if (isPool(getSource())) {
String baseUrl = "https://e621.net/" + getSource().getPath() + "?page=";
- return getChapters(getSource(), pg, baseUrl, "");
+ chapters = getChapters(getSource(), pg, baseUrl, "");
} else if (isSearchOrSet(getSource())) {
String baseUrl = "https://e621.net/posts/?page=";
String search = "&tags=" + getTagsFromUrl(getSource());
- return getChapters(getSource(), pg, baseUrl, search);
+
+ chapters = getChapters(getSource(), pg,
+ baseUrl, search);
}
- return new LinkedList<Entry<String, URL>>();
+ // sets and some pools are sorted in reverse order on the website
+ if (getSource().getPath().startsWith("/posts")) {
+ Collections.reverse(chapters);
+ }
+
+ return chapters;
}
private List<Entry<String, URL>> getChapters(URL source, Progress pg, String baseUrl, String parameters)
for (int i = 1; true; i++) {
URL url = new URL(baseUrl + i + parameters);
try {
- InputStream pageI = Instance.getCache().open(url, this, false);
+ InputStream pageI = Instance.getInstance().getCache().open(url, this, false);
try {
if (IOUtils.readSmallStream(pageI).contains("Nobody here but us chickens!")) {
break;
}
}
- // They are sorted in reverse order on the website
- Collections.reverse(urls);
return urls;
}
protected String getChapterContent(URL chapUrl, int number, Progress pg) throws IOException {
StringBuilder builder = new StringBuilder();
Document chapterNode = loadDocument(chapUrl);
- for (Element el : chapterNode.getElementsByTag("article")) {
+
+ Elements articles = chapterNode.getElementsByTag("article");
+
+ // sets and some pools are sorted in reverse order on the website
+ if (getSource().getPath().startsWith("/posts")) {
+ Collections.reverse(articles);
+ }
+
+ for (Element el : articles) {
builder.append("[");
builder.append(el.attr("data-file-url"));
builder.append("]<br/>");
@Override
protected URL getCanonicalUrl(URL source) {
+ // Convert search-pools into proper pools
+ if (source.getPath().equals("/posts") && source.getQuery() != null
+ && source.getQuery().startsWith("tags=pool%3A")) {
+ String poolNumber = source.getQuery()
+ .substring("tags=pool%3A".length());
+ try {
+ Integer.parseInt(poolNumber);
+ String base = source.getProtocol() + "://" + source.getHost();
+ if (source.getPort() != -1) {
+ base = base + ":" + source.getPort();
+ }
+ source = new URL(base + "/posts/" + poolNumber);
+ } catch (NumberFormatException e) {
+ // Not a simple ppol, skip
+ } catch (MalformedURLException e) {
+ // Cannot happen
+ }
+ }
+
if (isSetOriginalUrl(source)) {
try {
- Document doc = DataUtil.load(Instance.getCache().open(source, this, false), "UTF-8", source.toString());
+ Document doc = DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", source.toString());
for (Element shortname : doc.getElementsByClass("set-shortname")) {
for (Element el : shortname.getElementsByTag("a")) {
if (!el.attr("href").isEmpty())
}
}
} catch (IOException e) {
- Instance.getTraceHandler().error(e);
+ Instance.getInstance().getTraceHandler().error(e);
}
}