From: Christian Weiske Date: Thu, 14 Nov 2019 20:52:19 +0000 (+0100) Subject: script to batch-replace images in game files using a CSV mapping file X-Git-Url: https://git.cweiske.de/ouya-game-data.git/commitdiff_plain/0cfe6ed842fa9802630f71ece17be73c2a74e459 script to batch-replace images in game files using a CSV mapping file --- diff --git a/bin/replace-game-images-by-list b/bin/replace-game-images-by-list new file mode 100755 index 0000000..223e398 --- /dev/null +++ b/bin/replace-game-images-by-list @@ -0,0 +1,59 @@ +#!/usr/bin/env php +packageName; + replaceImage($data->media->discover); + replaceImage($data->media->large); + 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; + if (isset($mapping[$url])) { + $url = $mapping[$url]; + } +} +?>