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' => (int) $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 echo json_encode($gameData, JSON_PRETTY_PRINT) . "\n";
134 function details($mediaTiles)
137 foreach ($mediaTiles as $tile) {
138 if ($tile->type == 'video') {
146 'url' => $tile->urls->full,
147 'thumb' => $tile->urls->thumbnail,
156 file_put_contents('php://stderr', $msg . "\n");