code cleanup / jdoc
[nikiroo-utils.git] / src / be / nikiroo / fanfix / supported / Fimfiction.java
index 45455b610f2a05193746e4e8bffcf0163d10e55a..b5df2618ce671ddaf04d7f5b644c3110c721339b 100644 (file)
@@ -1,10 +1,10 @@
 package be.nikiroo.fanfix.supported;
 
-import java.awt.image.BufferedImage;
 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;
@@ -14,6 +14,7 @@ import java.util.Scanner;
 
 import be.nikiroo.fanfix.Instance;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Image;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
@@ -23,17 +24,12 @@ import be.nikiroo.utils.StringUtils;
  * 
  * @author niki
  */
-class Fimfiction extends BasicSupport {
+class Fimfiction extends BasicSupport_Deprecated {
        @Override
        protected boolean isHtml() {
                return true;
        }
 
-       @Override
-       public String getSourceName() {
-               return "FimFiction.net";
-       }
-
        @Override
        protected MetaData getMeta(URL source, InputStream in) throws IOException {
                MetaData meta = new MetaData();
@@ -42,14 +38,11 @@ class Fimfiction extends BasicSupport {
                meta.setAuthor(getAuthor(reset(in)));
                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("");
-               meta.setLang("EN");
+               meta.setLang("en");
                meta.setSubject("MLP");
-               meta.setType(getType().toString());
                meta.setImageDocument(false);
                meta.setCover(getCover(reset(in)));
 
@@ -83,13 +76,23 @@ class Fimfiction extends BasicSupport {
                                        break; // end of *this story* tags
                                }
 
-                               String tab[] = line.split("<li>");
-                               for (String subline : tab) {
-                                       subline = StringUtils.unhtml(subline).trim();
-                                       if (!subline.isEmpty() && !tags.contains(subline)) {
-                                               tags.add(subline);
+                               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();
                        }
                }
 
@@ -163,7 +166,7 @@ class Fimfiction extends BasicSupport {
                return getLine(in, "class=\"description-text bbcode\"", 1);
        }
 
-       private BufferedImage getCover(InputStream in) {
+       private Image getCover(InputStream in) {
                // Note: the 'og:image' is the SMALL cover, not the full version
                String cover = getLine(in, "class=\"story_container__story_image\"", 1);
                if (cover != null) {
@@ -198,7 +201,8 @@ class Fimfiction extends BasicSupport {
                                        break;
                                }
 
-                               if (line.startsWith("<a href=")) {
+                               if (line.startsWith("<a href=")
+                                               || line.contains("class=\"chapter-title\"")) {
                                        // Chapter name
                                        String name = line;
                                        int pos = name.indexOf('>');
@@ -220,24 +224,10 @@ class Fimfiction extends BasicSupport {
                                        }
 
                                        try {
-                                               final String key = name;
-                                               final URL value = new URL("http://www.fimfiction.net"
-                                                               + line);
-                                               urls.add(new Entry<String, URL>() {
-                                                       public URL setValue(URL value) {
-                                                               return null;
-                                                       }
-
-                                                       public String getKey() {
-                                                               return key;
-                                                       }
-
-                                                       public URL getValue() {
-                                                               return value;
-                                                       }
-                                               });
+                                               urls.add(new AbstractMap.SimpleEntry<String, URL>(name,
+                                                               new URL("http://www.fimfiction.net" + line)));
                                        } catch (MalformedURLException e) {
-                                               Instance.syserr(e);
+                                               Instance.getInstance().getTraceHandler().error(e);
                                        }
                                }
                        }