move path creation to separate file
[stouyapi.git] / bin / import-game-data.php
index 9dc05106bb6df5ede8f45fbf449e01ac125f89b7..11ed6b38993ba0e3297cad953ffba1bee7d690d3 100755 (executable)
@@ -7,6 +7,7 @@
  * @author Christian Weiske <cweiske@cweiske.de>
  */
 ini_set('xdebug.halt_level', E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
+require_once __DIR__ . '/functions.php';
 require_once __DIR__ . '/filters.php';
 if (!isset($argv[1])) {
     error('Pass the path to a "folders" file with game data json files folder names');
@@ -18,6 +19,7 @@ if (!is_file($foldersFile)) {
 
 //default configuration values
 $GLOBALS['packagelists'] = [];
+$GLOBALS['urlRewrites']  = [];
 $cfgFile = __DIR__ . '/../config.php';
 if (file_exists($cfgFile)) {
     include $cfgFile;
@@ -373,7 +375,7 @@ function buildAppDownload($game, $release)
             'fileSize'      => $release->size,
             'version'       => $release->uuid,
             'contentRating' => $game->contentRating,
-            'downloadLink'  => $release->url,
+            'downloadLink'  => rewriteUrl($release->url),
         ]
     ];
 }
@@ -418,7 +420,7 @@ function buildDetails($game)
             $mediaTiles[] = [
                 'type' => 'image',
                 'urls' => [
-                    'thumbnail' => $medium->thumb,
+                    'thumbnail' => $medium->thumb ?? $medium->url,
                     'full'      => $medium->url,
                 ],
             ];
@@ -697,11 +699,6 @@ function buildDiscoverGameTile($game)
     ];
 }
 
-function categoryPath($title)
-{
-    return str_replace(['/', '\\', ' ', '+', '?'], '_', $title);
-}
-
 function getAllAges($games)
 {
     $ages = [];
@@ -884,6 +881,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;