-
-
Save mjaschen/bd72be52ccad8979c0474e71ea23492f to your computer and use it in GitHub Desktop.
Create directory structure which mimics flickr's album structure including all photos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
define('FLICKR_DATA_DIR', '72157673198390467_ce7d69eecfc5_part1'); | |
define('OUTPUT_DIR', __DIR__ . '/output'); | |
$albums = json_decode(file_get_contents(FLICKR_DATA_DIR . '/albums.json')); | |
foreach ($albums->albums as $album) { | |
$albumDir = OUTPUT_DIR . '/' . str_replace(["'", '/'], ['', '-'], $album->title); | |
echo $albumDir . PHP_EOL; | |
if (!is_dir($albumDir) && !mkdir($albumDir, 0777, true) && !is_dir($albumDir)) { | |
throw new \RuntimeException(sprintf('Cannot create directory "%s"', $albumDir)); | |
} | |
foreach ($album->photos as $photoId) { | |
if ('0' === $photoId) { | |
continue; | |
} | |
$photo = json_decode(file_get_contents(sprintf('%s/photo_%s.json', FLICKR_DATA_DIR, $photoId))); | |
$file = $albumDir . '/' . pathinfo($photo->original, PATHINFO_BASENAME); | |
if (file_exists($file)) { | |
continue; | |
} | |
echo ' +-> ' . $photo->name . ', downloading ... '; | |
file_put_contents($file, fopen($photo->original, 'rb')); | |
echo 'done' . PHP_EOL; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
FLICKR_DATA_DIR
(contains the JSON files from a flickr take-out) andOUTPUT_DIR