Showing posts with label flickr perl photobox. Show all posts
Showing posts with label flickr perl photobox. Show all posts

Wednesday, 12 March 2008

flickr -> photobox transfer

SWMBO asked me if I could help transfer some of our flickr photos to photobox so that she can create and print an album. A quick Google seemed to find a few links for doing it the other way around, so it seemed like time to get knitting some perl!

Flickr has an API and photobox lets you use ftp to upload, so I thought I'd use the perl API to download the 4 sets that my wife had arranged on flickr. Anyway, here's the code with keys etc obscured. Sorry it's pretty rough and my perl is not too hot, but at least it works.


use Flickr::API;
use Data::Dumper;

my $api = new Flickr::API({'key' => 'your_flickr_api_key',
'secret' => 'your flickr_secret'});


my $frob = $api->execute_method('flickr.auth.getFrob', {
'api_key' => 'your_flickr_api_key',
});
my $f = $frob->{tree}->{children}[1]->{children}[0]->{content};

my $url = $api->request_auth_url("read", $f);
my $cmd = "C:/Progra~1/Mozill~1/firefox.exe \"$url\"";
system($cmd);
sleep(3);

my $token = $api->execute_method('flickr.auth.getToken', {
'api_key' => 'your_flickr_api_key',
'frob' => $f,
});

my $t = $token->{tree}->{children}[1]->{children}[1]->{children}[0]->{content};

my $response = $api->execute_method('flickr.photosets.getPhotos', {
'photoset_id' => '72157601397952579',
'auth_token' => $t,
});

my $ids = $response->{tree}->{children}[1]->{children};

for my $id (@$ids) {
if ($id->{attributes}) {
my $photo_id = $id->{attributes}->{id};
print "$photo_id\n";
my $sizes = $api->execute_method('flickr.photos.getSizes', {
'api_key' => 'your_flickr_api_key',
'photo_id' => $photo_id,
'auth_token' => $t,
});

my $s = $sizes->{tree}->{children}[1]->{children};
for my $size (@$s) {
if ($size->{attributes}) {
if ($size->{attributes}->{label} eq "Original") {
my $url = $size->{attributes}->{source};
print "$url\n";
my $c = "wget $url";
system($c);
}
}
}
}
}