fix cache, MangaLEL +search
[nikiroo-utils.git] / src / be / nikiroo / fanfix / searchable / Fanfiction.java
index 28c0d1be02613d8840f67ce55426ea7c71c98ad8..d25153eb28f6921ea7c4bc64410f384b6e812dd7 100644 (file)
@@ -141,10 +141,21 @@ class Fanfiction extends BasicSearchable {
        }
 
        @Override
-       public List<MetaData> search(String search) throws IOException {
+       public List<MetaData> search(String search, int page) throws IOException {
                String encoded = URLEncoder.encode(search.toLowerCase(), "utf-8");
-               return getStories(BASE_URL + "search/?ready=1&type=story&keywords="
-                               + encoded, null, null);
+               String url = BASE_URL + "search/?ready=1&type=story&keywords="
+                               + encoded + "&ppage=" + page;
+
+               return getStories(url, null, null);
+       }
+
+       @Override
+       public int searchPages(String search) throws IOException {
+               String encoded = URLEncoder.encode(search.toLowerCase(), "utf-8");
+               String url = BASE_URL + "search/?ready=1&type=story&keywords="
+                               + encoded;
+
+               return getPages(load(url, false));
        }
 
        @Override
@@ -193,11 +204,8 @@ class Fanfiction extends BasicSearchable {
         *            the document
         * 
         * @return the number of pages or -1 if unknown
-        * 
-        * @throws IOException
-        *             in case of I/O errors
         */
-       private int getPages(Document doc) throws IOException {
+       private int getPages(Document doc) {
                int pages = -1;
 
                if (doc != null) {
@@ -272,10 +280,11 @@ class Fanfiction extends BasicSearchable {
                                                        in.close();
                                                }
                                        } catch (Exception e) {
-                                               Instance.getTraceHandler()
-                                                               .error(new Exception(
-                                                                               "Cannot download cover for Fanfiction story in search mode",
-                                                                               e));
+                                               // Should not happen on Fanfiction.net
+                                               Instance.getTraceHandler().error(
+                                                               new Exception(
+                                                                               "Cannot download cover for Fanfiction story in search mode: "
+                                                                                               + meta.getTitle(), e));
                                        }
                                }
                        }