#!/usr/bin/perl
use warnings;
$help = 0;
if ($#ARGV == 2) {
$url=$ARGV[1];
$length=$ARGV[0];
$url=$ARGV[2];
} else {
$help = 1;
}
if ( $help == 1 ) {
print "Usage:\n";
print " $0 length url basename\n";
print " length is an integer representing the number of\n";
print " seconds to record.\n";
print " url is, put simply, the url to download\n";
print " basename is the base name for the file downloads\n";
print " for example, a basename of \"foo\" would result\n";
print " in files named as such:\n";
print " foo-year-mo-da-hr-mi-se.mp3\n";
print " it is often useful to have a path as your\n";
print " basename, this is allowed.\n\n";
exit 1;
}
$_=`date +-20%y-%m-%d-%H-%M-%S`;
chomp;
$filename = $basename.$_.".mp3";
$f=fork();
if($f==0){
#child
print "Writing ".$filename."...\n";
exec("curl","-s","-o",$basename.$_.".mp3",$url);
exit;
}
#parent
sleep $length;
kill 1,$f;
$_=`wc -c $filename`;
chomp;
($bytes,$file)=$_=~/\s+(\S+)\s+(\S+)/;
$kilobytes = $bytes/1024;
$file=$file; # get rid of that warning that says "Name "main::file" used only once: possible typo at /Users/ckastorff/bin/timenhbradiodl line 61."
print "Done - File Size is ".$bytes."B (".$kilobytes." KiB)\n";