Version 1.0.0
[fanfix.git] / src / be / nikiroo / fanfix / supported / Fanfiction.java
index 9be098d6b8bd67e5a419a10acd8fedc52ee5d695..7d4285b33e86109650e397c1d58358d54a9633a9 100644 (file)
@@ -43,6 +43,7 @@ class Fanfiction extends BasicSupport {
                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("");
@@ -123,6 +124,8 @@ class Fanfiction extends BasicSupport {
        }
 
        private String getAuthor(InputStream in) {
+               String author = null;
+
                int i = 0;
                @SuppressWarnings("resource")
                Scanner scan = new Scanner(in, "UTF-8");
@@ -131,12 +134,13 @@ class Fanfiction extends BasicSupport {
                        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) {
@@ -195,7 +199,7 @@ class Fanfiction extends BasicSupport {
                                                                        + "/" + url.getPath() + "/" + line;
                                                }
 
-                                               return getImage(null, line);
+                                               return getImage(this, null, line);
                                        }
                                }
                        }
@@ -219,39 +223,62 @@ class Fanfiction extends BasicSupport {
                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;
-                                                       }
-
-                                                       public String getKey() {
-                                                               return chapName;
-                                                       }
-                                               });
-                                       } catch (MalformedURLException e) {
-                                               Instance.syserr(new IOException("Cannot parse chapter "
-                                                               + i + " url: " + (base + i + suffix), e));
+               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());
+                                               }
+
+                                               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;