It creates a directory and download inside all the mp3 it founds on markleford page.Hovmod wrote:What's that?Ixox wrote:I just like to add that many of us use Garret automatic downloader and i'm afraid it can only download direct link.
So if there is no direct access you lose many listeners.
I think there is a windows wrapper somewhere but the perl code is:
Code: Select all
#!/usr/bin/perl
# KVR MIRRORING SCRIPT
# ver 0.3 by Garret Gengler
use LWP::UserAgent;
use URI::URL;
$|=1;
my $ua = LWP::UserAgent->new;
$ua->timeout(20);
$ua->env_proxy;
@nothing=();
$ua->requests_redirectable(\@nothing);
# get the date
my ($sec,$min,$hour,$mday,$mon,$year, $wday,$yday,$isdst) = localtime time;
#fix the 0 indexed month
++$mon;
# get the two digit year (by default perl returns 1900 less than reality)
# i.e., 2004 -> 104... so let's just subrtact another hundred
$year = $year - 100;
# build a directory name from the date
my $param=sprintf("%02d%02d", $year, $mon);
$localdir = "kvr-contest-$param/$filename";
print "KVR CONTEST AUTO-DOWNLOADER v0.3\n";
print "--------------------------------\n";
print "Downloading Markelford's latest playlist: (http://www.markleford.com/kvr/)\n";
print "Mirroring files locally into directory ./$localdir\n";
unlink "./radio.m3u";
$result = $ua->mirror('http://www.markleford.com/kvr/radio.jsp?month=' . $param, "radio.m3u");
if ($result->is_error) {
print "COULD NOT GET PLAYLIST$url\n";
}
else {
open (SOURCE, "radio.m3u") || die "Cannot open source file";
@urls = <SOURCE>;
chomp(@urls);
close (SOURCE);
mkdir $localdir;
foreach $url (@urls) {
($base,$filename) = $url =~ /(.+\/)(.+)/;
$origurl=$url;
$result=$ua->head($url);
# check if we got a file attachment... if so, parse to get the local filename... it won't be in the url<br>
if ($result->header('Content-Disposition')) {
# parse out a filename from this kind of thing:
# Content-Disposition: attachment; filename=02-05_Farlukar_-_Stop_the_skill.mp3
$line = $result->header('Content-Disposition');
$line =~ /filename=(.*)$/i;
$filename=$1;
}
# check if we got a redirect and failed... if so, try manually to follow it (fix up relative redirects)
if ($result->is_redirect) {
# manually fix up relative redirects to be absolute
my $dest = $result->header('Location');
# parse the url to get the remote server
my $urlobj = new URI::URL($url);
my $server = $urlobj->host();
# fix up the destination to get rid of spaces
$dest =~ s/ /%20/g;
# and get the true filename out of the dest url
($base,$filename) = $dest =~ /(.+\/)(.+)/;
# get rid of %20 markup for the filesystem
$filename =~ s/%20/ /g;
if ($dest =~ m|^http://|i) {
# okay, it looks absolute... pass this one as is
# print "\nRedirect, but absolute!\n";
$url = $dest;
}
elsif($dest =~ m|^/|) {
# it starts with a slash, so let's prefix with the server
$url = "http://$server$dest";
# print "\nRedirect, but relative!\n";
}
elsif ($dest) {
# no slash, so we need to add one
$url = "http://$server/$dest";
# print "\nRedirect, but relative with no slash!\n";
}
# print "\nREDIRECT $origurl\n to $url\n";
# print "mirroring $url as $filename\n";
}
$result=$ua->mirror($url, "$localdir/$filename");
if ($result->is_error) {
print "\nCOULD NOT MIRROR $url\n";
}
else {
print ".";
}
}
}
print "\nCompleted.\n";
print "Press ENTER to continue... ";
$keypress=<STDIN>;
Listen to some Monkey-Music
