Original Post
If you've ever wanted to stream your MP3 collection from your computer at home to a computer somewhere else like a coffee shop, you can use this perl script I whipped up to do this (which explains the indentation problems; cygwin, vi, ssh, xterm, and linux don't mix well). This script also randomizes the tracks. To use it, put your music files into a directory that's accessible to your web server. My linux system runs on my laptop which only has a 40GB drive, so I use Samba to mount the bigger drives in my desktop. go into your MP3 player and use a URL like: http://home/music.pl?path=/mnt/foo_mp3s Obviously, you'll need enough upload bandwidth to stream the file!
#!/usr/bin/perl
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
use CGI;
my $cgi = new CGI;
my $path = $cgi->param('path');
open( FILES, "ls $path |" );
while (<FILES>)
{
chomp;
$files[$i++] = $_;
}
$|=0;
while ( 1 )
{
$file = $files[rand($#files)];
$file = $path . "/" . $file;
open( INPUT, $file ) || die $!;
$size = (stat(INPUT))[7];
print "Content-length: $size\r\n";
print "Content-type: audio/mpeg\r\n\r\n";
seek INPUT, $start, 0;
while ( read(INPUT,$buf,1024 )>0 )
{
print $buf;
}
}