From: Christian Weiske Date: Wed, 13 Nov 2019 06:41:48 +0000 (+0100) Subject: Script to convert broken .apk download URLs to Internet Archive URLs X-Git-Url: https://git.cweiske.de/ouya-game-data.git/commitdiff_plain/cb55e12c63346488a8c47742a8f1374b46aa5fa8 Script to convert broken .apk download URLs to Internet Archive URLs --- diff --git a/bin/convert-internetarchive-apk-urls.php b/bin/convert-internetarchive-apk-urls.php new file mode 100755 index 0000000..d4dd307 --- /dev/null +++ b/bin/convert-internetarchive-apk-urls.php @@ -0,0 +1,50 @@ +#!/usr/bin/env php +releases as $release) { + if (parse_url($release->url, PHP_URL_HOST) != 'devs-ouya-tv-prod.s3.amazonaws.com') { + echo " release url ok\n"; + continue; + } + + $releaseNameFile = str_replace( + [' ', '(', ')', '!'], + ['_', '', '', ''], + $release->name + ); + $iaJsonFile = __DIR__ . '/../old-data/ia-data/' + . 'ouya_' . $gameData->packageName . '_' . $releaseNameFile . '.json'; + if (!file_exists($iaJsonFile)) { + echo " IA file not found: $iaJsonFile\n"; + continue; + } + $iaData = json_decode(file_get_contents($iaJsonFile)); + + $url = null; + foreach ($iaData->files as $iaFile) { + if ($iaFile->format == 'Android Package Archive') { + $iaSlug = basename($iaJsonFile, '.json'); + $url = 'https://archive.org/download/' . $iaSlug . '/' . rawurlencode($iaFile->name); + } + } + if ($url === null) { + echo " No apk found!\n"; + continue; + } + + $release->url = $url; + $changed = true; + } + + if ($changed) { + echo " Saving game data\n"; + file_put_contents($gameFile, json_encode($gameData, JSON_PRETTY_PRINT) . "\n"); + } +}