Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 118 lines (92 sloc) 2.914 kb
#!/usr/bin/perl
use strict;
use warnings;
use Data::GUID qw(guid_string);
use File::Basename;
use File::HomeDir ();
use File::Spec;
use Flickr::API;
use Flickr::Upload;
use Getopt::Long::Descriptive;
my ($opt, $usage) = describe_options(
"jgal2flickr %o",
[ "config|c=s", "alternate config file (defaults to ~/.flickrrc)",
{ default => File::Spec->catfile(File::HomeDir->my_home, '.flickrrc') } ],
[ "tag|t=s@", "tags to use for photos in this batch" ],
[ "captionfile|C=s", "alternate captions file", { default => '.captions' } ],
[ "prefix|p=s", "prefix titles with this", { default => '' } ],
);
### LOAD CONFIGURATION
# This is basically ripped off from Flickr-Upload's flickr_upload script.
my %config;
if (open my $config_file, '<', $opt->{config}) {
while (<$config_file>) {
chomp;
s/#.*$//; # strip comments
next unless m/^\s*([a-z_]+)=(.+)\s*$/io;
$config{$1} = $2;
}
} else {
die "no config file found; looked for $opt->{config}\n";
}
for (qw(key secret auth)) {
die "required parameter $_ not found in .flickrrc\n" unless $config{$_};
}
### CREATE GLOBALS
my $uploader = Flickr::Upload->new({
key => $config{key},
secret => $config{secret},
});
open my $captionfile, '<', $opt->{captionfile}
or die "couldn't open caption file '$opt->{captionfile}': $!\n";
my $tags = $opt->{tag} || [];
push @$tags, lc guid_string;
my @files;
FILE: while (my $line = <$captionfile>) {
chomp $line;
next unless $line =~ /^[^.]+\.jpg(?:\s|$)/i;
my ($filename, $title, $description) = split /\s*----\s*/, $line;
# Where filename is . it was a whole-gallery title; those would be sets, I
# guess, but making a set seems like overkill and, frankly... more work to
# script than to just do afterwards. -- rjbs, 2006-12-19
next FILE if $filename eq '.';
unless (-e $filename) {
warn "file '$filename' is in caption file but does not exist here\n";
next FILE;
}
unless (defined $title and length $title) {
$title = File::Basename::basename(lc $filename, '.jpg', '.png');
$title =~ s/_-/ /g;
}
push @files, {
filename => $filename,
title => "$opt->{prefix}$title",
description => $description,
};
}
my @uploaded;
my $i = 1;
UPLOAD: for my $file (@files) {
printf "Uploading %s, file %u of %u...\n",
$file->{filename},
$i++,
scalar @files;
my $id = $uploader->upload(
photo => $file->{filename},
auth_token => $config{auth},
tags => "@$tags",
title => $file->{title},
description => $file->{description},
is_public => 1,
is_friend => 1,
is_family => 1,
);
unless ($id) {
warn "...didn't succeed for file $file->{filename}: got no id\n";
next UPLOAD;
}
print "...done with file\n";
push @uploaded, $file;
}
printf "uploaded %u files\n", scalar @uploaded;
print "all uploads were tagged: @$tags\n";
Jump to Line
Something went wrong with that request. Please try again.