Streaming Audio: revisited (again)

Eric Dunbar eric.dunbar at gmail.com
Thu May 26 08:25:34 MDT 2005


On 5/26/05, Chris Kastorff <jckastorff at ix.netcom.com> wrote:
> I have found a better way (better than curl, kill) during my work
> with Perl. No killing, one cron job. The script linked to must be set
> +x (chmod +x file), and the first line should be set to #!/path/to/
> perl (which may be /usr/local/bin/perl or /usr/bin/perl or some other
> place. Run "which perl" to find out where it is if it's in your PATH.
> 
> Run it thru a cron job, something similar to this:
>     20    17    *    *    3    root    /path/to/timeradiodl 3600
> http://sample/stream /mnt/music/rip/music
> 
> (this starts a record of http://sample/stream out to /mnt/music/rip/
> music-date.mp3 on 5:27 PM Local Time on Wed for one hour. Depending
> on the system, "root" (the username) may or may not be required to be
> there.)
> 
> This works flawlessly on my OSX Machine (developed on 10.3.8, works
> on 10.4), don't know about linux, but it should work well.
> 
> The Script: http://pastebin.ca/12659
> 
> I probably should have used strict, but I was lazy.
> 
>     -Chris Kastorff (encryptio)

I've been having some success at downloading an OGG stream using
ogg123 and then encoding it to MP3 by piping the OGG output to lame.
I've even managed to get bash scripting to change the MP3 ID3 tags
according to the time the d/l is initiated (reminds me of SAS syntax)
:-) (i'm so proud I finally made *good* use of a man page... man
bash). Now I should learn how to use PERL since it seems to be
installed on so many OSes (does it come installed in OS X by
default?).

In case the link to the perl script disappears:

#!/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";


More information about the yellowdog-general mailing list