Add more warnings source to 1.6) and fix warnings
[nikiroo-utils.git] / src / be / nikiroo / fanfix / supported / Fanfiction.java
index 5f049e456c7d0b5930c01deef11227be9f7ecab5..fd514931848e72baca337054d0d3333f558e52a7 100644 (file)
@@ -13,7 +13,9 @@ import java.util.Map.Entry;
 import java.util.Scanner;
 
 import be.nikiroo.fanfix.Instance;
+import be.nikiroo.fanfix.bundles.Config;
 import be.nikiroo.fanfix.data.MetaData;
+import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.StringUtils;
 
 /**
@@ -72,7 +74,7 @@ class Fanfiction extends BasicSupport {
                return null;
        }
 
-       private List<String> getTags(InputStream in) throws IOException {
+       private List<String> getTags(InputStream in) {
                List<String> tags = new ArrayList<String>();
 
                String key = "title=\"Send Private Message\"";
@@ -124,6 +126,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");
@@ -132,12 +136,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) {
@@ -206,7 +211,8 @@ class Fanfiction extends BasicSupport {
        }
 
        @Override
-       protected List<Entry<String, URL>> getChapters(URL source, InputStream in) {
+       protected List<Entry<String, URL>> getChapters(URL source, InputStream in,
+                       Progress pg) {
                List<Entry<String, URL>> urls = new ArrayList<Entry<String, URL>>();
 
                String base = source.toString();
@@ -239,14 +245,17 @@ class Fanfiction extends BasicSupport {
                                                        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;
                                                                }
@@ -264,14 +273,17 @@ class Fanfiction extends BasicSupport {
                        final String chapName = getTitle(reset(in));
                        final URL chapURL = source;
                        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;
                                }
@@ -282,7 +294,8 @@ class Fanfiction extends BasicSupport {
        }
 
        @Override
-       protected String getChapterContent(URL source, InputStream in, int number) {
+       protected String getChapterContent(URL source, InputStream in, int number,
+                       Progress pg) {
                StringBuilder builder = new StringBuilder();
                String startAt = "class='storytext ";
                String endAt1 = "function review_init";
@@ -306,11 +319,26 @@ class Fanfiction extends BasicSupport {
                                if (builder.length() == 0) {
                                        int pos = line.indexOf("<hr");
                                        if (pos >= 0) {
-                                               line = line.substring(pos);
+                                               boolean chaptered = false;
+                                               for (String lang : Instance.getConfig()
+                                                               .getString(Config.CHAPTER).split(",")) {
+                                                       String chapterWord = Instance.getConfig()
+                                                                       .getStringX(Config.CHAPTER, lang);
+                                                       int posChap = line.indexOf(chapterWord + " ");
+                                                       if (posChap < pos) {
+                                                               chaptered = true;
+                                                               break;
+                                                       }
+                                               }
+
+                                               if (chaptered) {
+                                                       line = line.substring(pos);
+                                               }
                                        }
                                }
 
                                builder.append(line);
+                               builder.append(' ');
                        }
                }