Skip to content

Instantly share code, notes, and snippets.

@beppu
Created October 27, 2010 10:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beppu/648767 to your computer and use it in GitHub Desktop.
Save beppu/648767 to your computer and use it in GitHub Desktop.
If you ever need to bulk upload many URLs to imgur.com, this is the tool for you.
#!/usr/bin/env perl
use common::sense;
use AnyEvent;
use AnyEvent::HTTP;
use JSON;
# Get your API key here:
# http://imgur.com/register/api_anon
my $imgur_api_key = '69696969696969696969696969696969'; # XXX - replace me
my $imgur_upload = 'http://api.imgur.com/2/upload.json';
my $i = 0;
my $cv = AE::cv;
my @urls;
$cv->begin;
while (<>) {
$cv->begin;
chomp;
my $n = $i;
http_request(
post => $imgur_upload.'?key='.$imgur_api_key.'&type=url',
body => $_,
sub {
my ($data, $headers) = @_;
my $r = decode_json($data);
my $msg;
if ($r->{error}) {
$msg = "$r->{error}{message} $r->{error}{parameters}";
} else {
$msg = $r->{upload}{links}{original};
}
printf("%4d %s\n", $n, $msg);
$urls[$n] = $r->{upload}{links}{original};
$cv->end;
}
);
$i++;
}
$cv->end;
# print the new imgur urls in the order originally specified
$cv->recv;
print join("\n", @urls), "\n";
@tjohnson-github
Copy link

How Do you use it? Where are the list of images coming from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment