Play a MP3 list over HTTP

Sun 29 July 2007

All my mp3s are stored on my filesever. Normally I just mount the mp3 directory on my current workstation (either via NFS or Samba). I have some playlists too which store all files with relative paths (relative to the playlist location). This works fine.

But sometimes I want to have an easy way to listen to a playlist without mounting anything (eg. when using the laptop). So I made the mp3 files and playlists available on my local Apache webserver and use the following short CGI to get a playlist with http adresses to the file.


$WEBDIR = '/var/www';
$WEBSERVER = 'xerxes';

use CGI;
use File::Basename;

print "Content-type: audio/x-mpegurlrnrn";

$q = new CGI();

$list = $q->param('list');
$dir  = dirname($list);
$list = $WEBDIR.'/'.$list;

open (LIST, $list) or die("Could not read $list");
@m3u = <LIST>;
close LIST;

foreach $file (@m3u){
 $file = 'http://'.$WEBSERVER.$dir.'/'.$file;
 print "$filen";