Created
October 1, 2019 09:05
-
-
Save benkant/d33f3da2f0146515889cb8d26f435ed0 to your computer and use it in GitHub Desktop.
Download comfy gifs from Tumblr
This file contains hidden or 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 | |
# known issues: | |
# plenty, but | |
# GitHub can't render it properly: see the raw version which is `perltidy` | |
# hardcodes image size and only looks for gifs | |
# has an iterator that goes over 9000 regardless of whether it's still | |
# getting images or not | |
# it was written for a particular Tumblr, so may need tweaking for others | |
# | |
# try: | |
# ./tumblr-dl.pl 1041uuu | |
use strict; | |
use warnings; | |
use diagnostics; | |
use LWP::Simple; | |
my $site = $ARGV[0] | |
|| die( | |
"Usage:\n\t$0 tumblr-sitename\nNB: There's no need to specify the full URL" | |
); | |
my $baseurl = "https://$site.tumblr.com"; | |
print "Trying $baseurl..."; | |
my $test_response = get($baseurl); | |
if ( defined $test_response ) { | |
print " OK\n"; | |
} | |
else { | |
print " FAILED\n"; | |
exit(1); | |
} | |
mkdir "$site"; | |
foreach (my $i = 0 ; $i < 9999 ; $i += 50) { | |
my $url = "$baseurl/api/read?type=photo&num=50&start=$i"; | |
print "Retrieving $url\n"; | |
my $src = get($url); | |
foreach my $image ( $src =~ m{https://[^\s]+500\.gif}g ) { | |
my ($filename) = $image =~ m{/([^/]+500\.gif)}; | |
print "found $filename\n"; | |
getstore( $image, "$site/$filename" ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment