Last active
December 19, 2015 13:59
-
-
Save aufflick/5965622 to your computer and use it in GitHub Desktop.
Download all your ideveloper.tv videos
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/perl | |
use strict; | |
use warnings; | |
use WWW::Mechanize; | |
use LWP::UserAgent; | |
use Mozilla::CA; | |
if (@ARGV != 2 || $ARGV[0] !~ /@/) { | |
print STDERR "Pass in your ideveloper.tv email and password as first and second arguments."; | |
exit 1; | |
} | |
my $links_by_filename = get_download_links(); | |
for my $filename (sort keys %$links_by_filename) { | |
my $ua = LWP::UserAgent->new; | |
print STDERR "Downloading $filename: "; | |
my $link = $links_by_filename->{$filename}; | |
my $req = HTTP::Request->new( GET => $link->url ); | |
my $res = $ua->request($req, $filename); | |
if (!$res->is_success) { | |
print STDERR "Error: " . $res->status_line ."\n"; | |
} | |
else { | |
print STDERR "Done.\n"; | |
} | |
# need to refresh download links since they expire | |
$links_by_filename = get_download_links(); | |
} | |
print STDERR "All Downloads Attempted. Remember to tweet Scotty to tell him how much you appreciate all his hard work!\n"; | |
exit 0; | |
sub get_download_links { | |
my $mech = WWW::Mechanize->new; | |
$mech->get( 'http://my.ideveloper.tv' ); | |
$mech->submit_form( | |
fields => { | |
email => $ARGV[0], | |
password => $ARGV[1], | |
} | |
); | |
my @links = $mech->find_all_links( text_regex => qr/download/i ); | |
my %by_filename; | |
for my $link (@links) { | |
$link->url =~ m!/([^/\?]+)\?!; | |
my $filename = $1; | |
die "Couldn't figure out the filename for url: " . $link->url | |
if !$filename; | |
warn "Duplicate filename: " . $filename . " - you might be missing out on a download" | |
if exists $by_filename{$filename}; | |
$by_filename{$filename} = $link; | |
} | |
return \%by_filename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment