├── README.md ├── LICENSE └── download-all.php /README.md: -------------------------------------------------------------------------------- 1 | FlickrDownloadAll 2 | ================= 3 | 4 | PHP script to download all of your original sized photos from Flickr and sort them into folders based on your sets. 5 | 6 | ## Instructions 7 | 8 | 1. Checkout this repository 9 | 2. In the project directory, install `phpflickr` via composer: `composer require samwilson/phpflickr` 10 | 3. Follow the instructions written at the top of `download-all.php`. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tyler Hall 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /download-all.php: -------------------------------------------------------------------------------- 1 | 9 | // January 27, 2009 10 | // Released under the MIT License 11 | 12 | // === S T E P 1 === 13 | // Fill in your Flickr API information below. 14 | // You can generate the neccessary values by using phpFlickr's Auth Tool: 15 | // http://www.phpflickr.com/tools/auth/ 16 | define('API_KEY', ''); 17 | define('API_SECRET', ''); 18 | 19 | // === S T E P 2 === 20 | // Fill in your Flickr user ID. You can find it here: http://idgettr.com 21 | define('UID', ''); 22 | 23 | // === S T E P 3 === 24 | // Run the script via the command line using: "php download-all.php" 25 | 26 | require_once 'vendor/autoload.php'; 27 | $f = new \Samwilson\PhpFlickr\PhpFlickr(API_KEY, API_SECRET); 28 | 29 | // Get all of our photosets 30 | $sets = $f->photosets()->getList(UID); 31 | 32 | foreach($sets['photoset'] as $set) 33 | { 34 | echo "### " . $set['title'] . "\n"; 35 | @mkdir("photos/{$set['title']}", 0777, true); 36 | 37 | // Get all the photos in this set 38 | $photos = $f->photosets()->getPhotos($set['id'], UID); 39 | var_dump($photos); 40 | 41 | // And download each one... 42 | foreach($photos['photo'] as $photo) 43 | { 44 | $url = $f->photos()->getLargestSize($photo['id'])['source']; 45 | var_dump($url); 46 | 47 | if(!is_null($url)) 48 | { 49 | $dir = escapeshellarg("photos/{$set['title']}"); 50 | $filename = basename(parse_url($url, PHP_URL_PATH)); 51 | 52 | // Only download if file does not exist... 53 | if(!file_exists("photos/{$set['title']}/$filename")) 54 | shell_exec("cd $dir; /usr/bin/curl -O $url"); 55 | } 56 | 57 | // This helps stop the Flickr API from getting angry 58 | sleep(1); 59 | } 60 | } 61 | 62 | // Download all photos not in a set 63 | echo "### No Set\n"; 64 | $photos = $f->photos_getNotInSet(); 65 | foreach($photos['photos']['photo'] as $photo) 66 | { 67 | $url = null; 68 | $sizes = $f->photos_getSizes($photo['id']); 69 | foreach($sizes as $size) 70 | { 71 | if($size['label'] == 'Original') 72 | $url = $size['source']; 73 | } 74 | 75 | if(isset($url)) 76 | { 77 | @mkdir("photos/No Set", 0777, true); 78 | $dir = escapeshellarg("photos/No Set"); 79 | shell_exec("cd $dir; /usr/bin/curl -O $url"); 80 | } 81 | } 82 | 83 | echo "Done!\n"; 84 | --------------------------------------------------------------------------------