Merge commit '3519cb5c518d569235beaedfc3071cba45ec848d'
[nikiroo-utils.git] / src / be / nikiroo / fanfix / supported / E621.java
index 316ac2c2bcfbad54411467af2f34713e37772d8d..94010a73ae4b61165598b35b4f7ff8743b4b2e41 100644 (file)
@@ -3,6 +3,7 @@ package be.nikiroo.fanfix.supported;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLDecoder;
 import java.util.AbstractMap;
@@ -170,6 +171,13 @@ class E621 extends BasicSupport {
                        }
                }
 
+               if (isPool(source)) {
+                       try {
+                               return new URL(source.toString().replace("/pool/show/", "/pools/"));
+                       } catch (MalformedURLException e) {
+                       }
+               }
+
                return super.getCanonicalUrl(source);
        }
 
@@ -274,8 +282,12 @@ class E621 extends BasicSupport {
                Image image = null;
                List<Entry<String, URL>> chapters = getChapters(null);
                if (!chapters.isEmpty()) {
-                       URL url = chapters.get(0).getValue();
-                       image = bsImages.getImage(this, url);
+                       URL chap1Url = chapters.get(0).getValue();
+                       String imgsChap1 = getChapterContent(chap1Url, 1, null);
+                       if (!imgsChap1.isEmpty()) {
+                               imgsChap1 = imgsChap1.split("]")[0].substring(1).trim();
+                               image = bsImages.getImage(this, new URL(imgsChap1));
+                       }
                }
 
                return image;
@@ -287,7 +299,7 @@ class E621 extends BasicSupport {
        }
 
        private boolean isPool(URL url) {
-               return url.getPath().startsWith("/pools/");
+               return url.getPath().startsWith("/pools/") || url.getPath().startsWith("/pool/show/");
        }
 
        // set will be renamed into search by canonical url