e621: fix search-pool urls
authorNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 10:56:21 +0000 (12:56 +0200)
committerNiki Roo <niki@nikiroo.be>
Fri, 1 May 2020 10:56:21 +0000 (12:56 +0200)
src/be/nikiroo/fanfix/supported/E621.java

index 39bbe867d9eb2cdfc630c80df9393bc9bc47aba4..2b7e54d862f242c5cad72fdd8a3b58aee7a6e80f 100644 (file)
@@ -173,6 +173,25 @@ class E621 extends BasicSupport {
 
        @Override
        protected URL getCanonicalUrl(URL source) {
+               // Convert search-pools into proper pools
+               if (source.getPath().equals("/posts") && source.getQuery() != null
+                               && source.getQuery().startsWith("tags=pool%3A")) {
+                       String poolNumber = source.getQuery()
+                                       .substring("tags=pool%3A".length());
+                       try {
+                               Integer.parseInt(poolNumber);
+                               String base = source.getProtocol() + "://" + source.getHost();
+                               if (source.getPort() != -1) {
+                                       base = base + ":" + source.getPort();
+                               }
+                               source = new URL(base + "/posts/" + poolNumber);
+                       } catch (NumberFormatException e) {
+                               // Not a simple ppol, skip
+                       } catch (MalformedURLException e) {
+                               // Cannot happen
+                       }
+               }
+               
                if (isSetOriginalUrl(source)) {
                        try {
                                Document doc = DataUtil.load(Instance.getInstance().getCache().open(source, this, false), "UTF-8", source.toString());