Allow .apk URL rewrites
authorChristian Weiske <cweiske@cweiske.de>
Thu, 30 Apr 2020 14:17:26 +0000 (16:17 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 30 Apr 2020 14:17:26 +0000 (16:17 +0200)
So we can use our own server, even when the apk urls in the game data
still point to archive.org

bin/import-game-data.php
config.php.dist

index 9dc05106bb6df5ede8f45fbf449e01ac125f89b7..283c06b60e1e081762a8d8d56086fc5e709913b2 100755 (executable)
@@ -18,6 +18,7 @@ if (!is_file($foldersFile)) {
 
 //default configuration values
 $GLOBALS['packagelists'] = [];
+$GLOBALS['urlRewrites']  = [];
 $cfgFile = __DIR__ . '/../config.php';
 if (file_exists($cfgFile)) {
     include $cfgFile;
@@ -373,7 +374,7 @@ function buildAppDownload($game, $release)
             'fileSize'      => $release->size,
             'version'       => $release->uuid,
             'contentRating' => $game->contentRating,
-            'downloadLink'  => $release->url,
+            'downloadLink'  => rewriteUrl($release->url),
         ]
     ];
 }
@@ -884,6 +885,14 @@ function removeMakeGenres($genres)
     return $filtered;
 }
 
+function rewriteUrl($url)
+{
+    foreach ($GLOBALS['urlRewrites'] as $pattern => $replacement) {
+        $url = preg_replace($pattern, $replacement, $url);
+    }
+    return $url;
+}
+
 function writeJson($path, $data)
 {
     global $wwwDir;
index 11c34a2571b87fdc4908bb150ace658bb2e1c17e..030b1d609c3805c2925f7cc62622c0a9b0a17019 100644 (file)
@@ -3,6 +3,9 @@
  * Optional configuration file for import-game-data.php
  * Copy it to config.php and adjust it.
  */
+$GLOBALS['urlRewrites'] = [
+    '#^https://archive.org/download/#' => 'https://statics.ouya.world/ia/',
+];
 $GLOBALS['packagelists']["cweiske's picks"] = [
     'de.eiswuxe.blookid2',
     'com.cosmos.babyloniantwins',