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 9dc0510..283c06b 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 11c34a2..030b1d6 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',