Move "cweiskes picks" to configuration file
[stouyapi.git] / bin / import-game-data.php
index 260773383e18d812cb26764d7773d3722dd691b4..9dc05106bb6df5ede8f45fbf449e01ac125f89b7 100755 (executable)
@@ -16,11 +16,12 @@ if (!is_file($foldersFile)) {
     error('Given path is not a file: ' . $foldersFile);
 }
 
-$GLOBALS['packagelists']['cweiskepicks'] = [
-    'de.eiswuxe.blookid2',
-    'com.cosmos.babyloniantwins',
-    'com.inverseblue.skyriders',
-];
+//default configuration values
+$GLOBALS['packagelists'] = [];
+$cfgFile = __DIR__ . '/../config.php';
+if (file_exists($cfgFile)) {
+    include $cfgFile;
+}
 
 $wwwDir = __DIR__ . '/../www/';
 
@@ -152,10 +153,13 @@ function buildDiscover(array $games)
         $data, 'Best rated',
         filterBestRated($games, 10)
     );
-    addDiscoverRow(
-        $data, "cweiske's picks",
-        filterByPackageNames($games, $GLOBALS['packagelists']['cweiskepicks'])
-    );
+
+    foreach ($GLOBALS['packagelists'] as $listTitle => $listPackageNames) {
+        addDiscoverRow(
+            $data, $listTitle,
+            filterByPackageNames($games, $listPackageNames)
+        );
+    }
 
     addDiscoverRow(
         $data, 'Special',
@@ -380,7 +384,7 @@ function buildProduct($product)
         return null;
     }
     return [
-        'type'          => 'entitlement',
+        'type'          => $product->type ?? 'entitlement',
         'identifier'    => $product->identifier,
         'name'          => $product->name,
         'description'   => $product->description ?? '',
@@ -419,10 +423,12 @@ function buildDetails($game)
                 ],
             ];
         } else {
-            $mediaTiles[] = [
-                'type' => 'video',
-                'url'  => $medium->url,
-            ];
+            if (!isUnsupportedVideoUrl($medium->url)) {
+                $mediaTiles[] = [
+                    'type' => 'video',
+                    'url'  => $medium->url,
+                ];
+            }
         }
     }
 
@@ -586,11 +592,11 @@ function buildSearch($games)
 function dummyEncrypt($data)
 {
     return [
-        'key'  => base64_encode('0123456789abcdef') . "\n",
-        'iv'   => 't3jir1LHpICunvhlM76edQ==' . "\n",//random bytes
+        'key'  => base64_encode('0123456789abcdef'),
+        'iv'   => 't3jir1LHpICunvhlM76edQ==',//random bytes
         'blob' => base64_encode(
             json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
-        ) . "\n",
+        ),
     ];
 }
 
@@ -852,6 +858,16 @@ function getPromotedProduct($game)
     return null;
 }
 
+/**
+ * vimeo only work with HTTPS now,
+ * and the OUYA does not support SNI.
+ * We get SSL errors and no video for them :/
+ */
+function isUnsupportedVideoUrl($url)
+{
+    return strpos($url, '://vimeo.com/') !== false;
+}
+
 function removeMakeGames(array $games)
 {
     return filterByGenre($games, 'Tutorials', true);