#!/usr/bin/env php packageName; replaceImage($data->media->discover); if (count($data->media->screenshots ?? [])) { $pos = 0; foreach ($data->media->screenshots as &$url) { replaceImage($url); } } if (count($data->media->details ?? [])) { $pos = 0; foreach ($data->media->details as $detail) { if ($detail->type == 'image') { replaceImage($detail->url); replaceimage($detail->thumb); } } } file_put_contents($file, json_encode($data, JSON_PRETTY_PRINT) . "\n"); } function replaceImage(&$url) { global $mapping; preg_match('#https://www.filepicker.io/api/file/([^/]+)/convert\?w=720#', $url, $matches); if (isset($matches[1])) { $url = 'https://d3e4aumcqn8cw3.cloudfront.net/api/file/' . $matches[1]; } if (strlen($url) == 55) { preg_match('#https://www.filepicker.io/api/file/([^/]+)$#', $url, $matches); if (isset($matches[1])) { $url = 'https://d3e4aumcqn8cw3.cloudfront.net/api/file/' . $matches[1]; } } if (isset($mapping[$url])) { $url = $mapping[$url]; } } ?>