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 $package = basename($detailsFile, '.json');
52 if (file_exists($downloadFile)) {
53 $downloadJson = file_get_contents($downloadFile);
54 if ($downloadJson === false || trim($downloadJson) === '') {
55 error('Download file is empty');
57 $downloadData = json_decode($downloadJson);
58 if ($downloadData === null) {
59 error('Download JSON cannot de loaded');
61 $downloadUrl = $downloadData->app->downloadLink;
65 //fetch download URL from internet archive files
66 $version = $appsData->app->versionNumber;
67 $iaJsonFile = __DIR__ . '/../old-data/ia-data/'
68 . 'ouya_' . $package . '_' . $version . '.json';
69 if (!file_exists($iaJsonFile)) {
70 error('No download file given, and no internet archive version found');
72 $iaData = json_decode(file_get_contents($iaJsonFile));
73 foreach ($iaData->files as $iaFile) {
74 if ($iaFile->format == 'Android Package Archive') {
75 $iaSlug = basename($iaJsonFile, '.json');
76 $downloadUrl = 'https://archive.org/download/' . $iaSlug . '/' . $iaFile->name;
79 if ($downloadUrl === null) {
80 error('No .apk download URL found in internet archive json file');
87 $developerUuid = null;
88 if (isset($detailsData->developer->url)) {
89 parse_str(parse_url($detailsData->developer->url, PHP_URL_QUERY), $devParams);
90 $developerUuid = $devParams['developer'];
94 'packageName' => $package,
95 'title' => $appsData->app->title,
96 'description' => $appsData->app->description,
97 'players' => $appsData->app->gamerNumbers,
98 'genres' => $appsData->app->genres,
102 'name' => $appsData->app->versionNumber,
103 'versionCode' => (int) $detailsData->apk->versionCode,
104 'uuid' => $appsData->app->latestVersion,
105 'date' => $appsData->app->publishedAt,
106 'url' => $downloadUrl,
107 'size' => isset($downloadData->app->fileSize)
108 ? intval($downloadData->app->fileSize)
109 : intval($appsData->app->apkFileSize),
110 'md5sum' => $appsData->app->md5sum,
111 'publicSize' => $appsData->app->publicSize,
112 'nativeSize' => $appsData->app->nativeSize,
117 'discover' => 'http://ouya.cweiske.de/game-images/' . strtolower($package) . '/discover',
118 'large' => $appsData->app->mainImageFullUrl,
119 'video' => $appsData->app->videoUrl,
120 'screenshots' => $appsData->app->filepickerScreenshots,
121 'details' => details($detailsData->mediaTiles),
125 'uuid' => $developerUuid,
126 'name' => $appsData->app->developer,
127 'supportEmail' => $appsData->app->supportEmailAddress != ''
128 ? $appsData->app->supportEmailAddress : null,
129 'supportPhone' => $appsData->app->supportPhone,
130 'founder' => $appsData->app->founder,
133 'contentRating' => $appsData->app->contentRating,
134 'website' => $appsData->app->website,
135 'firstPublishedAt' => $appsData->app->firstPublishedAt,
136 'inAppPurchases' => $detailsData->inAppPurchases,
137 'overview' => $appsData->app->overview,
138 'premium' => $appsData->app->premium,
141 'likeCount' => $appsData->app->likeCount,
142 'average' => $appsData->app->ratingAverage,
143 'count' => $appsData->app->ratingCount,
147 if (isset($appsData->app->promotedProduct)) {
148 $gameData['products'][] = [
150 'identifier' => $appsData->app->promotedProduct->identifier,
151 'name' => $appsData->app->promotedProduct->name,
152 'description' => $appsData->app->promotedProduct->description,
153 'localPrice' => $appsData->app->promotedProduct->localPrice,
154 'originalPrice' => $appsData->app->promotedProduct->originalPrice,
155 'currency' => $appsData->app->promotedProduct->currency,
159 echo json_encode($gameData, JSON_PRETTY_PRINT) . "\n";
161 function details($mediaTiles)
164 foreach ($mediaTiles as $tile) {
165 if ($tile->type == 'video') {
173 'url' => $tile->urls->full,
174 'thumb' => $tile->urls->thumbnail,
183 file_put_contents('php://stderr', $msg . "\n");