Download Flickr Photos

If you were looking for an easy way to download a bunch of Flickr photos, have a look at the perl script I wrote for exactly that purpose.

Features

  • Can download from photo stream as well as sets
  • Downloads photos in maximum available resolution
  • Saves downloaded photos to a hierarchically structured folder in the same directory as the script
  • Works on Linux, can be modified to work on Windows/Mac

Example Use

The following will download all photos in maximum resolution from the user Aspyrantis’ photostream.

$> ./download-flickr-set.pl
*** DOWNLOAD FLICKR SET 1.0 ***
By Pieter Hiele

Enter the URL of the Flickr set you wish to download (e.g. http://www.flickr.com/photos/aspyrantis/sets/72157626467366362/).
URL: http://www.flickr.com/photos/aspyrantis/

Pictures: 44
Pages: 3

Downloading http://farm8.staticflickr.com/7055/6970675053_73c1593807_b.jpg
Downloading http://farm8.staticflickr.com/7061/6824545696_541018cec0_b.jpg
Downloading http://farm8.staticflickr.com/7210/6964900687_a91818dd31_b.jpg
Downloading http://farm8.staticflickr.com/7203/6964894589_7edf7c37d0_b.jpg

$> ./download-flickr-set.pl
*** DOWNLOAD FLICKR SET 1.0 ***
By Pieter Hiele

Enter the URL of the Flickr set you wish to download (e.g. http://www.flickr.com/photos/aspyrantis/sets/72157626467366362/).
URL: http://www.flickr.com/photos/grandvelasrivieramaya/sets/72157625876516828/

Pictures: 150
Pages: 3

Downloading http://farm6.staticflickr.com/5161/5375897713_466604a009_z.jpg

Code
Note! The script has only been tested very superficially and on a linux machine.

#! /usr/bin/perl
use LWP::Simple;
use POSIX ();

my $aantal = 0;
my $pages = 0;

system("clear");
print "*** DOWNLOAD FLICKR SET 1.0 ***\nBy Pieter Hiele\n\n";
print "Enter the URL of the Flickr set you wish to download (e.g. http://www.flickr.com/photos/aspyrantis/sets/72157626467366362/).\nURL: ";
$url = <>;
chomp($url);

$set = get($url);

$set =~ /<div class=\"Results\">\((\d+)/;
$aantal = $1;

while($set =~ /data-track="page-(\d+)/g) {
$pages = $1;
};
print "Pictures: $aantal\n";
print "Pages: $pages\n";
print "\n";

#parse page 1
parse_page($set);

#parse other pages
for($i=2;$i<=$pages;$i++) {
parse_page(get("$url?page=$i"));
}

sub parse_page {
my ($content) = @_;
while($content =~ /<a data-track=\"photo-click\" href=\"(.*?)\"/g) {
@parts = split("\/in\/",$1);
$original = get("http://www.flickr.com".$parts[0]."/sizes/o/in/".$parts[1]);
$original =~ /<img src=\"http:\/\/farm(.*)\.jpg/;
print "Downloading http://farm$1.jpg\n";
system("wget http://farm$1.jpg -P $url -a logfile.txt");
}
}

Comments

Please leave your feedback in the comments below.

4 thoughts on “Download Flickr Photos

  1. Hi, great script. But, there is on problem with it. It doesn’t download the largest photo available when there is Large1024 (_l) and Large1600 (_h). Other then that, your script is awesome.

    1. Hi Doug,
      Do you have any idea how I can get the meta data associated with each image in this script? I am interested in the tags and other info about each image.
      Is it possible?
      Thanks,
      Sharath

  2. Nice!
    simple and effective.
    The other tools I found could only download photos stored from an account I own but not from another account who shared his photos with me.

Leave a Reply

Your email address will not be published. Required fields are marked *