Handle large filepicker URLs in image replacer
authorChristian Weiske <cweiske@cweiske.de>
Fri, 15 Nov 2019 06:32:38 +0000 (07:32 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 15 Nov 2019 06:35:59 +0000 (07:35 +0100)
bin/replace-game-images-by-list

index 223e398..74df284 100755 (executable)
@@ -52,6 +52,19 @@ foreach ($files as $file) {
 function replaceImage(&$url)
 {
     global $mapping;
+
+    preg_match('#https://www.filepicker.io/api/file/([^/]+)/convert\?w=720#', $url, $matches);
+    if (isset($matches[1])) {
+        $url = 'https://d3e4aumcqn8cw3.cloudfront.net/api/file/' . $matches[1];
+    }
+
+    if (strlen($url) == 55) {
+        preg_match('#https://www.filepicker.io/api/file/([^/]+)$#', $url, $matches);
+        if (isset($matches[1])) {
+            $url = 'https://d3e4aumcqn8cw3.cloudfront.net/api/file/' . $matches[1];
+        }
+    }
+
     if (isset($mapping[$url])) {
         $url = $mapping[$url];
     }