Better URL entries + fix for FimFicAPI:
authorNiki Roo <niki@nikiroo.be>
Fri, 10 Aug 2018 08:44:34 +0000 (10:44 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 10 Aug 2018 08:44:34 +0000 (10:44 +0200)
- URL entries now generated with SimpleEntry (instead of anonymous class)
- FimFictionAPI now sorts the chapter names correctly

src/be/nikiroo/fanfix/supported/E621.java
src/be/nikiroo/fanfix/supported/EHentai.java
src/be/nikiroo/fanfix/supported/Fanfiction.java
src/be/nikiroo/fanfix/supported/Fimfiction.java
src/be/nikiroo/fanfix/supported/FimfictionApi.java
src/be/nikiroo/fanfix/supported/YiffStar.java

index 298ccf16bee07f2b2d3a3124a34543c095dfe2f3..f299ee7ff8d14b00df5cd3ca12318237a37d32ef 100644 (file)
@@ -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<String, URL>() {
-                               @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<String, URL>(Integer
+                                       .toString(i), new URL(source.toString() + "?page=" + i)));
                }
 
                return urls;
index 2fe70d9714a7cbe396a42f2a572a020f1b18c219..9a09f077bf82b2145bd7242d52fbbb1b0d8cc266 100644 (file)
@@ -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<String, URL>() {
-                               @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<String, URL>(Integer
+                                       .toString(i + 1), new URL(source.toString() + "?p=" + i)));
                }
 
                return urls;
index 4193fa01e92eca1acc4f572ea3efb20eb4386ae8..9b749bc6753e1efc92c2ffb48d1d6a83f1981b1e 100644 (file)
@@ -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<String, URL>() {
-                                                               @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<String, URL>(
+                                                                       name.trim(), new URL(base + i + suffix)));
                                                } catch (MalformedURLException e) {
                                                        Instance.getTraceHandler()
                                                                        .error(new IOException(
index 1f72031b9e745c89df00625543cfe66208a196bc..792f66baf11e1423287d4138b07c8f2fca95ef51 100644 (file)
@@ -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<String, URL>() {
-                                                       @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<String, URL>(name,
+                                                               new URL("http://www.fimfiction.net" + line)));
                                        } catch (MalformedURLException e) {
                                                Instance.getTraceHandler().error(e);
                                        }
index 6ef8a2cc70d8bb65e7c32b4b94fce81d96f07bea..52678e402a2e1c98b65560b12a0a8df825424252 100644 (file)
@@ -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<Entry<String, URL>> getChapters(URL source, InputStream in,
                        Progress pg) {
-               List<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
-
-               chapterNames = new HashMap<Integer, String>();
-               chapterContents = new HashMap<Integer, String>();
+               chapterNames = new TreeMap<Integer, String>();
+               chapterContents = new TreeMap<Integer, String>();
 
                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 = "<br/>* * *<br/>" + notes;
                                }
-                               
+
                                chapterNames.put(number, title);
-                               chapterContents
-                                               .put(number, content + notes);
-
-                               urls.add(new Entry<String, URL>() {
-                                       @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<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
+               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;
        }
 
index 2996ce993770993d18460bcfe4b10c9ddcb8e470..92d44fe9beaa9f997c6d1375af2f4c332b0ee496 100644 (file)
@@ -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<String, URL>() {
-                                               @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<String, URL>(
+                                                       StringUtils.unhtml(line).trim(), guest(link)));
                                }
                        }
                }