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 game-details.json game-apps.json game-apps-download.json'
15 if (!isset($argv[1])) {
16 error('details json file parameter missing (api/v1/details?app=...');
18 $detailsFile = $argv[1];
20 if (!isset($argv[2])) {
21 error('apps json file parameter missing (api/v1/apps/xxx');
25 if (!isset($argv[3])) {
26 error('apps download json file parameter missing (api/v1/apps/xxx/download');
28 $downloadFile = $argv[3];
32 $detailsJson = file_get_contents($detailsFile);
33 if ($detailsJson === false || trim($detailsJson) === '') {
34 error('Details file is empty');
36 $detailsData = json_decode($detailsJson);
37 if ($detailsData === null) {
38 error('Details JSON cannot de loaded');
41 $appsJson = file_get_contents($appsFile);
42 if ($appsJson === false || trim($appsJson) === '') {
43 error('Apps file is empty');
45 $appsData = json_decode($appsJson);
46 if ($appsData === null) {
47 error('App JSON cannot de loaded');
50 $downloadJson = file_get_contents($downloadFile);
51 if ($downloadJson === false || trim($downloadJson) === '') {
52 error('Download file is empty');
54 $downloadData = json_decode($downloadJson);
55 if ($downloadData === null) {
56 error('Download JSON cannot de loaded');
61 $package = basename($detailsFile, '.json');
63 $developerUuid = null;
64 if (isset($detailsData->developer->url)) {
65 parse_str(parse_url($detailsData->developer->url, PHP_URL_QUERY), $devParams);
66 $developerUuid = $devParams['developer'];
70 'packageName' => $package,
71 'title' => $appsData->app->title,
72 'description' => $appsData->app->description,
73 'players' => $appsData->app->gamerNumbers,
74 'genres' => $appsData->app->genres,
78 'name' => $appsData->app->versionNumber,
79 'versionCode' => $detailsData->apk->versionCode,
80 'uuid' => $appsData->app->latestVersion,
81 'date' => $appsData->app->publishedAt,
82 'url' => $downloadData->app->downloadLink,
83 'size' => (int) $downloadData->app->fileSize,
84 'md5sum' => $appsData->app->md5sum,
85 'publicSize' => $appsData->app->publicSize,
86 'nativeSize' => $appsData->app->nativeSize,
91 'discover' => 'http://ouya.cweiske.de/game-images/' . strtolower($package) . '/discover',
92 'large' => $appsData->app->mainImageFullUrl,
93 'video' => $appsData->app->videoUrl,
94 'screenshots' => $appsData->app->filepickerScreenshots,
95 'details' => details($detailsData->mediaTiles),
99 'uuid' => $developerUuid,
100 'name' => $appsData->app->developer,
101 'supportEmail' => $appsData->app->supportEmailAddress,
102 'supportPhone' => $appsData->app->supportPhone,
103 'founder' => $appsData->app->founder,
106 'contentRating' => $appsData->app->contentRating,
107 'website' => $appsData->app->website,
108 'firstPublishedAt' => $appsData->app->firstPublishedAt,
109 'inAppPurchases' => false,//FIXME: we would need discover data here
110 'overview' => $appsData->app->overview,
111 'premium' => $appsData->app->premium,
114 'likeCount' => $appsData->app->likeCount,
115 'average' => $appsData->app->ratingAverage,
116 'count' => $appsData->app->ratingCount,
120 if (isset($appsData->app->promotedProduct)) {
121 $gameData['products'][] = [
123 'identifier' => $appsData->app->promotedProduct->identifier,
124 'name' => $appsData->app->promotedProduct->name,
125 'description' => $appsData->app->promotedProduct->description,
126 'localPrice' => $appsData->app->promotedProduct->localPrice,
127 'originalPrice' => $appsData->app->promotedProduct->originalPrice,
128 'currency' => $appsData->app->promotedProduct->currency,
132 $iaDataFiles = glob(__DIR__ . '/../old-data/ia-data/ouya_' . $package . '_*.json');
133 if (count($iaDataFiles)) {
135 foreach ($iaDataFiles as $iaJsonFile) {
136 $iaData = json_decode(file_get_contents($iaJsonFile));
137 foreach ($iaData->files as $iaFile) {
138 if ($iaFile->format == 'Android Package Archive') {
139 $iaSlug = basename($iaJsonFile, '.json');
140 $iaFile->url = 'https://archive.org/download/' . $iaSlug . '/' . $iaFile->name;
141 $versionName = explode('_', $iaSlug)[2];
142 $iaPkg[$versionName] = $iaFile;
147 //update existing release
148 $exVersion = $gameData['releases'][0]['name'];
149 if (isset($iaPkg[$exVersion])) {
150 $gameData['releases'][0]['url'] = $iaPkg[$exVersion]->url;
151 unset($iaPkg[$exVersion]);
153 foreach ($iaPkg as $iaVersion => $iaApk) {
154 $gameData['releases'][] = [
155 'name' => $iaVersion,
157 'date' => '2010-01-01T00:00:00Z',//gmdate('c', $iaApk->mtime),
158 'url' => $iaApk->url,
159 'size' => $iaApk->size,
160 'md5sum' => $iaApk->md5,
161 'publicSize' => 0,//FIXME
162 'nativeSize' => 0,//FIXME
165 //var_dump($iaPkg, $gameData);die();
169 echo json_encode($gameData, JSON_PRETTY_PRINT) . "\n";
171 function details($mediaTiles)
174 foreach ($mediaTiles as $tile) {
175 if ($tile->type == 'video') {
183 'url' => $tile->urls->full,
184 'thumb' => $tile->urls->thumbnail,
193 file_put_contents('php://stderr', $msg . "\n");