Skip to content

Instantly share code, notes, and snippets.

@aufflick
Last active December 19, 2015 13:59
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 aufflick/5965622 to your computer and use it in GitHub Desktop.
Save aufflick/5965622 to your computer and use it in GitHub Desktop.
Download all your ideveloper.tv videos
#!/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