#!/usr/bin/perl -w

use strict;

#
# Adjustable parameters
#
my $srcdir = '/root/mp3';
my $htbase = '/var/www/html';
my $urlbase = 'mp3';

#
# Get the full playlist.
#
my @all = `find $srcdir -type f -name '*.mp3' | sort -f`;
map { s/^$srcdir\///; } @all;
open(FH,">$srcdir/index") or die;
print FH @all;
close FH;
chomp @all;

open(FH,">$htbase/mp3.html") or die;
print FH qq{<html><head><title>mp3 playlist</title></head>\n};
print FH qq{<body vlink="#0000ff">\n};
my $i = 0;
foreach (@all) {
	my $dir = `dirname "$_"`;
	chomp $dir;
	my $name = `mp3info -p '%t' "$srcdir/$_" 2>/dev/null` ||
		`basename "$_"`;
	chomp $name;
	
	my $disptitle = "$dir/$name";
	$disptitle =~ s#/# / #go;

	print FH qq{<a href="/cgi-bin/play?$i" target="track">$disptitle</a><br>\n};
	$i++;
}
print FH qq{</body></html>\n};
close FH;

