Created
October 27, 2010 10:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How Do you use it? Where are the list of images coming from?