Skip to content

Instantly share code, notes, and snippets.

@xatier
Last active March 27, 2017 03:41
Show Gist options
  • Save xatier/8266710 to your computer and use it in GitHub Desktop.
Save xatier/8266710 to your computer and use it in GitHub Desktop.
iTunesU url extracker
#!/usr/bin/env perl
use 5.014;
use URI::Escape;
use WWW::Mechanize;
use List::MoreUtils qw(uniq);
use utf8;
my $want;
$want = join " ", @ARGV if (@ARGV);
$want //= "stanford";
$want = uri_escape($want);
my $search = "https://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?submit=seeAllLockups&restrict=false&entity=iTunesUCourse&media=iTunesU&term=$want";
say "[+] Query: $want";
say "[+] Send request: $search";
my $mech = WWW::Mechanize->new();
$mech->add_header('User-agent' => 'iTunes/10.6.3.25');
$mech->get($search);
my $doc = $mech->content();
my @cources = ();
my @lines = split '\n', $doc;
for my $line (@lines) {
if ($line =~ /course-subscribe/ and $line =~ "https://itunes.apple.com/us/course") {
push @cources, [$2, $1] if ($line =~ /<a href=\"(.*?)\">(.*?)<\/a>/);
}
}
my $ctr = 0;
say scalar @cources . " cource(s) found!\n\n";
for (@cources) {
say "[+]: No: $ctr";
say "[+]: $_->[0]";
say "[+]: $_->[1]";
say "";
$ctr++;
}
print "\n\n[?]: Which one do you want? No: ";
my $no = <STDIN>;
chomp($no);
exit if $no !~ /\d+/;
say "\n";
say "-"x50;
say "[+]: You choosed No. $no";
say "[+]: $cources[$no]->[0]";
say "[+]: $cources[$no]->[1]";
say "-"x50;
say "\n";
my @materials = ();
$mech->get($cources[$no]->[1]);
$doc = $mech->content();
@lines = split '\n', $doc;
for my $line (@lines) {
if ($line =~ /anonymous-download-url/) {
push @materials, [$1, $2, $4]
if $line =~ /item-name=\"(.*?)\" kind=\"(.*?)\" adam-id=\"(.*?)\" anonymous-download-url=\"(.*?)\"/;
}
}
$ctr = 0;
for (@materials) {
say "[+]: No: $ctr";
say "[+]: [$_->[1]] $_->[0]";
say "[+]: $_->[2]";
say "";
$ctr++;
}
print "\n\n[?]: Which one do you want? No: ";
$no = <STDIN>;
chomp($no);
exit if $no !~ /\d+/;
say "\n";
say "-"x50;
say "[+]: You choosed No. $no";
say "[+]: $materials[$no]->[0]";
say "[+]: $materials[$no]->[1]";
say "[+]: $materials[$no]->[2]";
say "-"x50;
say "\n";
$mech->get($materials[$no]->[2]);
$doc = $mech->content();
open F, ">tmp.xml";
print F $doc;
system("open -a 'Google Chrome' tmp.xml");
close F;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment