4 * Convert OUYA storefront data to a game json file
6 * @author Christian Weiske <cweiske@cweiske.de>
8 if (isset($argv[1]) && in_array($argv[1], ['-h', '--help'])) {
10 'Usage: convert-original.php ouya-game-details.json ouya-game-download.json'
15 if (!isset($argv[1])) {
16 error('details json file parameter missing');
18 $detailsFile = $argv[1];
20 if (!isset($argv[2])) {
21 error('download json file parameter missing');
23 $downloadFile = $argv[2];
27 $detailsJson = file_get_contents($detailsFile);
28 if ($detailsJson === false || trim($detailsJson) === '') {
29 error('Details file is empty');
31 $detailsData = json_decode($detailsJson);
32 if ($detailsData === null) {
33 error('Details JSON cannot de loaded');
36 $downloadJson = file_get_contents($downloadFile);
37 if ($downloadJson === false || trim($downloadJson) === '') {
38 error('Download file is empty');
40 $downloadData = json_decode($downloadJson);
41 if ($downloadData === null) {
42 error('Download JSON cannot de loaded');
45 $package = basename($detailsFile, '.json');
48 'uuid' => $detailsData->app->uuid,
49 'package' => $package,
50 'title' => $detailsData->app->title,
51 'description' => $detailsData->app->description,
52 'players' => $detailsData->app->gamerNumbers,
53 'genres' => $detailsData->app->genres,
57 'name' => $detailsData->app->versionNumber,
58 'uuid' => $detailsData->app->latestVersion,
59 'date' => $detailsData->app->publishedAt,
60 'url' => $downloadData->app->downloadLink,
61 'size' => $downloadData->app->fileSize,
62 'md5sum' => $detailsData->app->md5sum,
63 'publicSize' => $detailsData->app->publicSize,
64 'nativeSize' => $detailsData->app->nativeSize,
69 'discover' => 'http://ouya.cweiske.de/game-images/' . strtolower($package) . '/discover',
70 'large' => newImage($detailsData->app->mainImageFullUrl),
71 'video' => $detailsData->app->videoUrl,
72 'screenshots' => newImages($detailsData->app->filepickerScreenshots),
76 'name' => $detailsData->app->developer,
77 'supportEmail' => $detailsData->app->supportEmailAddress,
78 'supportPhone' => $detailsData->app->supportPhone,
79 'founder' => $detailsData->app->founder,
82 'contentRating' => $detailsData->app->contentRating,
83 'website' => $detailsData->app->website,
84 'firstPublishedAt' => $detailsData->app->firstPublishedAt,
85 'inAppPurchases' => false,//FIXME: we would need discover data here
86 'overview' => $detailsData->app->overview,
87 'premium' => $detailsData->app->premium,
90 'likeCount' => $detailsData->app->likeCount,
91 'average' => $detailsData->app->ratingAverage,
92 'count' => $detailsData->app->ratingCount,
96 if (isset($detailsData->app->promotedProduct)) {
97 $gameData['products'][] = [
99 'identifier' => $detailsData->app->promotedProduct->identifier,
100 'name' => $detailsData->app->promotedProduct->name,
101 'description' => $detailsData->app->promotedProduct->description,
102 'localPrice' => $detailsData->app->promotedProduct->localPrice,
103 'originalPrice' => $detailsData->app->promotedProduct->originalPrice,
104 'currency' => $detailsData->app->promotedProduct->currency,
108 $iaDataFiles = glob(__DIR__ . '/../old-data/ia-data/ouya_' . $package . '_*.json');
109 if (count($iaDataFiles)) {
111 foreach ($iaDataFiles as $iaJsonFile) {
112 $iaData = json_decode(file_get_contents($iaJsonFile));
113 foreach ($iaData->files as $iaFile) {
114 if ($iaFile->format == 'Android Package Archive') {
115 $iaSlug = basename($iaJsonFile, '.json');
116 $iaFile->url = 'https://archive.org/download/' . $iaSlug . '/' . $iaFile->name;
117 $versionName = explode('_', $iaSlug)[2];
118 $iaPkg[$versionName] = $iaFile;
123 //update existing release
124 $exVersion = $gameData['releases'][0]['name'];
125 if (isset($iaPkg[$exVersion])) {
126 $gameData['releases'][0]['url'] = $iaPkg[$exVersion]->url;
127 unset($iaPkg[$exVersion]);
129 foreach ($iaPkg as $iaVersion => $iaApk) {
130 $gameData['releases'][] = [
131 'name' => $iaVersion,
133 'date' => '2010-01-01T00:00:00Z',//gmdate('c', $iaApk->mtime),
134 'url' => $iaApk->url,
135 'size' => $iaApk->size,
136 'md5sum' => $iaApk->md5,
137 'publicSize' => 0,//FIXME
138 'nativeSize' => 0,//FIXME
141 var_dump($iaPkg, $gameData);die();
145 echo json_encode($gameData, JSON_PRETTY_PRINT) . "\n";
147 function newImage($imageUrl)
151 if ($mapping === null) {
152 $hdl = fopen(__DIR__ . '/../old-data/map-game-images.csv', 'r');
154 error('Cannot load image url map file');
157 while ($data = fgetcsv($hdl, 4096, ',')) {
158 if (count($data) == 2) {
159 $mapping[$data[0]] = $data[1];
163 return $mapping[$imageUrl] ?? $imageUrl;
166 function newImages($urls)
169 foreach ($urls as $url) {
170 $new[] = newImage($url);
177 file_put_contents('php://stderr', $msg . "\n");