#!/usr/bin/perl
#
# author: Patrick Stein aka Jolly (original script from ortwin)
# usage: insert into crontab will download missing files to current working dir or the given dir ( arg ).
use itunescredentials;
$login = itunescredentials::login;
$password = itunescredentials::password;
my $destinationdirectory = pop @ARGV;
if( -d $destinationdirectory )
{
chdir($destinationdirectory);
}
$curlcmd='curl';
$itmsserver = 'https://itts.apple.com';
$htmloutput = `$curlcmd "$itmsserver/cgi-bin/WebObjects/Piano.woa"`;
if( $htmloutput =~ m/form\s+method="post"\s+action="([^"]+)">/io )
{
$action = $1;
print "action url: $action\n";
if( $htmloutput =~ //io )
{
$wosid=$1;
}
}
else
{
print STDERR __LINE__."could not find login action:\n$htmloutput\n";
exit 1;
}
$htmloutput = `$curlcmd -d "theAccountName=$login" -d "theAccountPW=$password" -d "theAuxValue=" -d "1.Continue.x=0" -d "1.Continue.y=0" -d "wosid=wosid" "$itmsserver$action"`;
if( $htmloutput =~ m/form\s+method="post"\s+name="frmVendorPage"\s+action="([^"]+)">/io )
{
$action = $1;
print "action url: $action\n";
}
else
{
print STDERR __LINE__."could not find frmVendorPage action:\n$htmloutput\n";
exit 1;
}
$action = $1;
print "action url: $action\n";
foreach my $datetype ('Weekly','Daily')
{
my $htmloutput = `$curlcmd -d "11.7=Summary" -d "11.9=$datetype" -d "hiddenDayOrWeekSelection=$datetype" -d "hiddenSubmitTypeName=ShowDropDown" -d "wosid=wosid" "$itmsserver$action" ` ;
if( $htmloutput =~ m/form\s+method="post"\s+name="frmVendorPage"\s+action="([^"]+)">/io )
{
$subaction = $1;
print "subaction url: $subaction\n";
}
else
{
print STDERR __LINE__."could not find frmVendorPage action:\n$htmloutput\n";
exit 1;
}
if( $htmloutput =~ m/