Skip to content

Instantly share code, notes, and snippets.

@secondfolder
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secondfolder/191e54881f8064e1a96d to your computer and use it in GitHub Desktop.
Save secondfolder/191e54881f8064e1a96d to your computer and use it in GitHub Desktop.
suckTheBundle: a humpthebundle.com bulk downloader
#!/usr/bin/env perl
# suckTheBundle: a humpthebundle.com bulk downloader by secondfolder
use warnings;
use strict;
use JSON::XS;
use LWP::Simple qw(getstore);
use LWP 5.64;
# use Data::Dumper;
use File::Copy;
use File::Path qw(make_path);
my $manifestURL = "https://www.humpthebundle.com/data/index/manifest.json";
my $baseURL = "http://grundle.humpthebundle.com/";
# file suffix for currenly downloading file
my $dlExt = ".downloading";
my $key = $ARGV[0];
while( !$key ){
print "API key plz: ";
$key = <>;
chomp $key;
}
# Save path (currently releative to cwd)
my $savePath = "humpTheBundle-downloads/";
my $browser = LWP::UserAgent->new;
my $response = $browser->get($manifestURL);
die "Error at $manifestURL\n ", $response->status_line, "\n Aborting"
unless $response->is_success;
my $manifest = JSON::XS->new->utf8->decode( $response->decoded_content );
my $url = $baseURL;
# loop through all partners
for my $partner ( @{$manifest->{partners}} ){
my $tierNum = 0;
# loop though all tiers (how many tiers you have accces to depends on how much you payed)
for my $tier ( @{$partner->{tiers}} ){
$tierNum++;
my $url = $url."tier$tierNum/";
# download both videos and photos
for my $type ( keys $tier->{members} ){
# loop over all items in type
for my $download ( @{$tier->{members}->{$type}} ){
# make url local to this block
my $url = $url;
if( ! exists $download->{source} ){
$url .= "source/";
} elsif( $download->{source} eq "1080p" ){
$url .= "source/";
} elsif( $download->{source} eq "720p" ){
$url .= "mp4_720p/";
} else {
die "Unreconised source: $download->{source}";
}
# add file name (minus extention)
$url .= $download->{file};
my $savePath = $savePath.$type;
# if the path to save the file dosen't exist, create it.
if( !-d $savePath ){
make_path($savePath);
}
my $fileExt;
if( $type eq "videos" ){
$fileExt = ".mp4";
} elsif ( $type eq "photos" ){
$fileExt = ".zip";
} else {
die "Unreconised type: $type";
}
# add extention to file name
$url .= $fileExt;
$savePath .= "/$download->{file}$fileExt";
$url .= "?key=".$key;
print "Saving $url to $savePath\n";
# if file already exists, go to next file
if( -e $savePath ){
print " Already downloaded\n";
next;
}
# add temprary download, suffix
$savePath .= $dlExt;
if( getstore($url,$savePath) == 200 ){
print " Done\n";
# when file is finished downloading remove temp suffix
move ($savePath, $savePath =~ s/(.*)$dlExt$/$1/r);
} else {
print " Failed :(\n";
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment