From 517cbabc9010666314618ca79fd4352f86de5b35 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Tue, 25 Feb 2020 21:47:09 +0100 Subject: [PATCH] Script to replace vimeo videos with .mp4 from internet archive Related to: https://github.com/ouya-saviors/ouya-game-data/issues/18 --- bin/inject-ia-videos.php | 87 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 bin/inject-ia-videos.php diff --git a/bin/inject-ia-videos.php b/bin/inject-ia-videos.php new file mode 100644 index 00000000..a989347d --- /dev/null +++ b/bin/inject-ia-videos.php @@ -0,0 +1,87 @@ +packageName . "\n"; + + $iaFiles = glob($iaJsonDir . '/ouya_' . $game->packageName . '_*.json'); + if (!count($iaFiles)) { + echo "No internet archive files for " . $game->packageName . "\n"; + continue; + } + + $modified = false; + $iamp4s = []; + foreach ($iaFiles as $iaJsonFile) { + $iaData = json_decode(file_get_contents($iaJsonFile)); + $parts = explode('_', basename($iaJsonFile, '.json')); + + $url = null; + foreach ($iaData->files as $iaFile) { + if ($iaFile->format != 'MPEG4' || $iaFile->source != 'original') { + continue; + } + + $iaSlug = basename($iaJsonFile, '.json'); + $url = 'https://archive.org/download/' . $iaSlug . '/' + . rawurlencode($iaFile->name); + + if (!preg_match('# - ([0-9]+)\\.mp4#', $iaFile->name, $matches)) { + echo " Cannot find vimeo ID in name " . $iaFile->name . "\n"; + continue; + } + $vimeoId = $matches[1]; + + $iamp4s[$vimeoId] = $url; + } + + if (count($iamp4s) == 0) { + echo " no .mp4 in $iaJsonFile\n"; + continue; + } + } + + echo " found " . count($iamp4s) . " videos in IA!\n"; + + foreach ($game->media as $medium) { + if ($medium->type != 'video') { + continue; + } + if (substr($medium->url, 0, 18) != 'https://vimeo.com/') { + continue; + } + + $vimeoId = substr($medium->url, 18); + if (isset($iamp4s[$vimeoId])) { + echo " Replacing " . $medium->url . " with " . $iamp4s[$vimeoId] . "\n"; + $modified = true; + $medium->url = $iamp4s[$vimeoId]; + } + } + + if (!$modified) { + continue; + } + + file_put_contents( + $file, + json_encode($game, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n" + ); + echo " written\n"; +} +?>