From ce297a794b1b7d3aa4e9234a6511dd9fe7216656 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Fri, 10 Aug 2018 10:44:34 +0200 Subject: [PATCH] Better URL entries + fix for FimFicAPI: - URL entries now generated with SimpleEntry (instead of anonymous class) - FimFictionAPI now sorts the chapter names correctly --- src/be/nikiroo/fanfix/supported/E621.java | 21 ++------ src/be/nikiroo/fanfix/supported/EHentai.java | 21 ++------ .../nikiroo/fanfix/supported/Fanfiction.java | 23 ++------- .../nikiroo/fanfix/supported/Fimfiction.java | 22 ++------ .../fanfix/supported/FimfictionApi.java | 50 +++++++------------ src/be/nikiroo/fanfix/supported/YiffStar.java | 21 ++------ 6 files changed, 34 insertions(+), 124 deletions(-) diff --git a/src/be/nikiroo/fanfix/supported/E621.java b/src/be/nikiroo/fanfix/supported/E621.java index 298ccf16..f299ee7f 100644 --- a/src/be/nikiroo/fanfix/supported/E621.java +++ b/src/be/nikiroo/fanfix/supported/E621.java @@ -3,6 +3,7 @@ package be.nikiroo.fanfix.supported; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.List; import java.util.Map.Entry; @@ -219,24 +220,8 @@ class E621 extends BasicSupport_Deprecated { } for (int i = 1; i <= last; i++) { - final String key = Integer.toString(i); - final URL value = new URL(source.toString() + "?page=" + i); - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public URL getValue() { - return value; - } - - @Override - public String getKey() { - return key; - } - }); + urls.add(new AbstractMap.SimpleEntry(Integer + .toString(i), new URL(source.toString() + "?page=" + i))); } return urls; diff --git a/src/be/nikiroo/fanfix/supported/EHentai.java b/src/be/nikiroo/fanfix/supported/EHentai.java index 2fe70d97..9a09f077 100644 --- a/src/be/nikiroo/fanfix/supported/EHentai.java +++ b/src/be/nikiroo/fanfix/supported/EHentai.java @@ -4,6 +4,7 @@ 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.List; import java.util.Map.Entry; @@ -229,24 +230,8 @@ class EHentai extends BasicSupport_Deprecated { } for (int i = 0; i <= last; i++) { - final String key = Integer.toString(i + 1); - final URL value = new URL(source.toString() + "?p=" + i); - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public URL getValue() { - return value; - } - - @Override - public String getKey() { - return key; - } - }); + urls.add(new AbstractMap.SimpleEntry(Integer + .toString(i + 1), new URL(source.toString() + "?p=" + i))); } return urls; diff --git a/src/be/nikiroo/fanfix/supported/Fanfiction.java b/src/be/nikiroo/fanfix/supported/Fanfiction.java index 4193fa01..9b749bc6 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; @@ -49,7 +50,7 @@ class Fanfiction extends BasicSupport_Deprecated { meta.setPublisher(getSourceName()); meta.setUuid(source.toString()); meta.setLuid(""); - meta.setLang("en"); //TODO! + meta.setLang("en"); // TODO! meta.setSubject(getSubject(reset(in))); meta.setType(getType().toString()); meta.setImageDocument(false); @@ -244,24 +245,8 @@ class Fanfiction extends BasicSupport_Deprecated { } try { - final String chapName = name.trim(); - final URL chapURL = new URL(base + i + suffix); - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public URL getValue() { - return chapURL; - } - - @Override - public String getKey() { - return chapName; - } - }); + urls.add(new AbstractMap.SimpleEntry( + name.trim(), new URL(base + i + suffix))); } catch (MalformedURLException e) { Instance.getTraceHandler() .error(new IOException( diff --git a/src/be/nikiroo/fanfix/supported/Fimfiction.java b/src/be/nikiroo/fanfix/supported/Fimfiction.java index 1f72031b..792f66ba 100644 --- a/src/be/nikiroo/fanfix/supported/Fimfiction.java +++ b/src/be/nikiroo/fanfix/supported/Fimfiction.java @@ -4,6 +4,7 @@ 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; @@ -231,25 +232,8 @@ class Fimfiction extends BasicSupport_Deprecated { } try { - final String key = name; - final URL value = new URL("http://www.fimfiction.net" - + line); - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public String getKey() { - return key; - } - - @Override - public URL getValue() { - return value; - } - }); + urls.add(new AbstractMap.SimpleEntry(name, + new URL("http://www.fimfiction.net" + line))); } catch (MalformedURLException e) { Instance.getTraceHandler().error(e); } diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index 6ef8a2cc..52678e40 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -3,11 +3,13 @@ package be.nikiroo.fanfix.supported; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.AbstractMap; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.TreeMap; import be.nikiroo.fanfix.Instance; import be.nikiroo.fanfix.bundles.Config; @@ -132,9 +134,9 @@ class FimfictionApi extends BasicSupport_Deprecated { meta.setSubject("MLP"); meta.setType(getType().toString()); meta.setImageDocument(false); - - String coverImageLink = - getKeyJson(json, 0, "type", "story", "cover_image", "full"); + + String coverImageLink = getKeyJson(json, 0, "type", "story", + "cover_image", "full"); if (!coverImageLink.trim().isEmpty()) { meta.setCover(getImage(this, null, coverImageLink.trim())); } @@ -166,10 +168,8 @@ class FimfictionApi extends BasicSupport_Deprecated { @Override protected List> getChapters(URL source, InputStream in, Progress pg) { - List> urls = new ArrayList>(); - - chapterNames = new HashMap(); - chapterContents = new HashMap(); + chapterNames = new TreeMap(); + chapterContents = new TreeMap(); int pos = 0; while (pos >= 0) { @@ -182,34 +182,21 @@ class FimfictionApi extends BasicSupport_Deprecated { final String title = getKeyJson(json, pos, "title"); String notes = getKeyJson(json, pos, "authors_note_html"); String content = getKeyJson(json, pos, "content_html"); - + if (!notes.trim().isEmpty()) { notes = "
* * *
" + notes; } - + chapterNames.put(number, title); - chapterContents - .put(number, content + notes); - - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public String getKey() { - return title; - } - - @Override - public URL getValue() { - return null; - } - }); + chapterContents.put(number, content + notes); } } + List> urls = new ArrayList>(); + for (String title : chapterNames.values()) { + urls.add(new AbstractMap.SimpleEntry(title, null)); + } + return urls; } @@ -311,10 +298,9 @@ class FimfictionApi extends BasicSupport_Deprecated { result = wip.substring(0, pos); } } - - result = result.replace("\\t", "\t") - .replace("\\\"", "\""); - + + result = result.replace("\\t", "\t").replace("\\\"", "\""); + return result; } diff --git a/src/be/nikiroo/fanfix/supported/YiffStar.java b/src/be/nikiroo/fanfix/supported/YiffStar.java index 2996ce99..92d44fe9 100644 --- a/src/be/nikiroo/fanfix/supported/YiffStar.java +++ b/src/be/nikiroo/fanfix/supported/YiffStar.java @@ -4,6 +4,7 @@ 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; @@ -206,24 +207,8 @@ class YiffStar extends BasicSupport_Deprecated { link = source.getProtocol() + "://" + source.getHost() + link; } - final URL value = guest(link); - final String key = StringUtils.unhtml(line).trim(); - urls.add(new Entry() { - @Override - public URL setValue(URL value) { - return null; - } - - @Override - public URL getValue() { - return value; - } - - @Override - public String getKey() { - return key; - } - }); + urls.add(new AbstractMap.SimpleEntry( + StringUtils.unhtml(line).trim(), guest(link))); } } } -- 2.27.0