Category: | Audio |
Author/Contact Info | Hero Zzyzzx |
Description: | A neat little mod_perl handler to create a recursive mp3/ogg playlist, to be fed to clients (like winamp or freeamp) that support streaming. The ONLY thing it does is recurse the directory you define and create a single playlist for all the .mp3/.ogg files it finds. That's it. This playlist then gets passed to whatever audio player you have defined to handle the 'audio/x-mpegurl' mime type. It ain't pretty, but it's short, sweet, and works well (for me). If you want to stream .ogg files, freeamp does this very well. I'm sure I'm not using File::Find completely correctly. I could get rid of those damn globals if I could figure out how to pass variables to the sub used by find(). Usage: Download this and put it in your apache modules path, or PerlRequire it in. Define it as a handler for your mp3 files under your web root directory, thusly:
Restart apache. From now on, every request to http://yourserver.com/mp3 will create a playlist to be streamed by your player. I know about Apache::MP3, and I'd use it if I could, but it doesn't support .ogg files. This is just a quick hack that may turn into a larger project at some point. |
package PlayListServer; use strict; use File::Find; use vars qw/ $path_to_webroot $mp3path $servername/; $|=0; sub handler{ my $r=shift; my $s = $r->server; $mp3path='/mp3/'; $path_to_webroot='/www/dan'; $servername=$s->server_hostname; $r->content_type('audio/x-mpegurl'); $r->send_http_header(); find(\&make_list_to_print,$path_to_webroot.$mp3path); return 200; } sub make_list_to_print{ if (($File::Find::name =~ /\.ogg|\.mp3$/io)){ my $temp = $File::Find::dir.'/'.$_; $temp =~ s/$path_to_webroot(.*)/$1/io; print 'http://'.$servername.$temp."\n"; } } 1; |
|
---|