Category subtitles config option
[stouyapi.git] / bin / import-game-data.php
index 0073983aa7339849c51f050cd56922486b03a214..44f9b635f10c0d1d4b2a7a259e87fc84145b57c1 100755 (executable)
@@ -18,6 +18,8 @@ if (!is_file($foldersFile)) {
 }
 
 //default configuration values
+$GLOBALS['baseUrl']      = 'http://ouya.cweiske.de/';
+$GLOBALS['categorySubtitles'] = [];
 $GLOBALS['packagelists'] = [];
 $GLOBALS['urlRewrites']  = [];
 $cfgFile = __DIR__ . '/../config.php';
@@ -175,8 +177,8 @@ function buildDiscover(array $games)
         filterLastAdded($games, 10)
     );
     addDiscoverRow(
-        $data, 'Best rated',
-        filterBestRated($games, 10),
+        $data, 'Best rated games',
+        filterBestRatedGames($games, 10),
         true
     );
 
@@ -191,6 +193,7 @@ function buildDiscover(array $games)
         $data, 'Special',
         [
             'Best rated',
+            'Best rated games',
             'Most rated',
             'Random',
             'Last updated',
@@ -200,6 +203,10 @@ function buildDiscover(array $games)
         'api/v1/discover-data/' . categoryPath('Best rated') . '.json',
         buildSpecialCategory('Best rated', filterBestRated($games, 99))
     );
+    writeJson(
+        'api/v1/discover-data/' . categoryPath('Best rated games') . '.json',
+        buildSpecialCategory('Best rated games', filterBestRatedGames($games, 99))
+    );
     writeJson(
         'api/v1/discover-data/' . categoryPath('Most rated') . '.json',
         buildSpecialCategory('Most rated', filterMostDownloaded($games, 99))
@@ -284,15 +291,21 @@ function buildDiscoverCategory($name, $games)
         'rows'  => [],
         'tiles' => [],
     ];
-    addDiscoverRow(
-        $data, 'Last Updated',
-        filterLastUpdated($games, 10)
-    );
-    addDiscoverRow(
-        $data, 'Best rated',
-        filterBestRated($games, 10),
-        true
-    );
+    if (isset($GLOBALS['categorySubtitles'][$name])) {
+        $data['stouyapi']['subtitle'] = $GLOBALS['categorySubtitles'][$name];
+    }
+
+    if (count($games) >= 20) {
+        addDiscoverRow(
+            $data, 'Last Updated',
+            filterLastUpdated($games, 10)
+        );
+        addDiscoverRow(
+            $data, 'Best rated',
+            filterBestRated($games, 10),
+            true
+        );
+    }
 
     $games = sortByTitle($games);
     $chunks = array_chunk($games, 4);
@@ -431,7 +444,7 @@ function buildAppDownload($game, $release)
             'fileSize'      => $release->size,
             'version'       => $release->uuid,
             'contentRating' => $game->contentRating,
-            'downloadLink'  => rewriteUrl($release->url),
+            'downloadLink'  => $release->url,
         ]
     ];
 }
@@ -904,6 +917,15 @@ function addMissingGameProperties($game)
             'url'  => $qrUrlPath,
         ];
     }
+
+    //rewrite urls from Internet Archive to our servers
+    $game->discover = rewriteUrl($game->discover);
+    foreach ($game->media as $medium) {
+        $medium->url = rewriteUrl($medium->url);
+    }
+    foreach ($game->releases as $release) {
+        $release->url = rewriteUrl($release->url);
+    }
 }
 
 /**