script to print all image urls from game files
[ouya-game-data.git] / bin / print-image-urls.php
1 #!/usr/bin/env php
2 <?php
3 /**
4  * - s3.amazonaws.com are still ok
5  * - d3e4aumcqn8cw3.cloudfront.net URLs are down
6  *   - 8522 mirrored by cweiske
7  *   - 2039 missing
8  *     - 583 in internet archive
9  * - filepicker-URLs have the same IDs as cloudfront, and are down :/
10  */
11 $files = glob(__DIR__ . '/../games/*.json');
12 foreach ($files as $file) {
13     $data = json_decode(file_get_contents($file));
14     $package = $data->packageName;
15     collectFile($package, $data->media->discover, 'discover');
16     collectFile($package, $data->media->large, 'large');
17     if (count($data->media->screenshots ?? [])) {
18         $pos = 0;
19         foreach ($data->media->screenshots as $url) {
20             collectFile($package, $url, 'screenshot-' . ++$pos);
21         }
22     }
23     if (count($data->media->details ?? [])) {
24         $pos = 0;
25         foreach ($data->media->details as $detail) {
26             if ($detail->type == 'image') {
27                 collectFile($package, $detail->url, 'detail-' . ++$pos);
28                 collectFile($package, $detail->thumb, 'detail-' . $pos . '-thumb');
29             }
30         }
31     }
32     //die();
33 }
34
35 function collectFile($package, $url, $type)
36 {
37     preg_match('#https://www.filepicker.io/api/file/([^/]+)/convert\?w=720#', $url, $matches);
38     if (isset($matches[1])) {
39         $url = 'https://d3e4aumcqn8cw3.cloudfront.net/api/file/' . $matches[1];
40     }
41     echo $url . "\n";
42     return;
43     echo $package
44         . "," . $type
45         . "," . $url
46         . "\n";
47 }
48 ?>