#!/usr/bin/perl
# This script is under the status of the GPL
# It's biodegradable, feature-full, footloose and fancy-free
 
# Written by Em Tonkin, em@typodemon.com

# set the below variable to the path you want to list the mp3s on. 
# Note that you can use this for other patterns than just mp3s
$filepath="/mnt/bilbo2/";

# to use this for, ie, avis or wav files, change this variable I just invented
$filetype="*.mp3";
# Example would be $filetype="*.wav";

# Set this variable to 'NULL' ie $URL=NULL; if you don't want to print a HTTP URL
$URL=1;
$WEBADDRESS="http://localhost/";

# Set this variable to 'NULL' if you don't want to print a SAMBA URL
$SMBURL=NULL;

# Root URL for Samba ie. //goldfish/ if goldfish is your machine's name
$SMBADDRESS="//fiskarspinguin/";

# Because this works by running 'find ' and because I am too lazy to sort it out 
# by reading lots of 'find' manual pages, you will have to write in here the part 
# of the URL you want excluded from the 'real' root of your system.
# ie. if I am using this to look at mp3s which for me are in /mnt/share/music/, 
# and I have this shared via samba or apache as http://goldfish/music, I want 
# to exclude the /mnt/share/ from the URL.

$URL_TO_EXCLUDE="/mnt/bilbo2/";

# Background colour, sorry, color, of the HTML page
$body_bg_colour="white";

# Below this is all just code. Abandon Hope All Ye Who Enter Here

print "<HTML><HEAD><TITLE>MP3s</TITLE></HEAD><BODY BGCOLOR=\"$body_bg_colour\">\n";
$command="find $filepath -iname '$filetype'";
@names = `$command`;


print "<p>Listing of mp3s from $filepath </p>\n";
foreach $myline (@names){
   $myline2=$myline;
   $myline=~s/^$URL_TO_EXCLUDE//g;
   $myline2=~/$filepath(.*)/i;
   $title=${1};
   $myline=~s/\n//g;
   $title=~s/\n//g;

   if($URL ne NULL){
   	print "<a href=\"$WEBADDRESS$myline\"> ";
   	# if you want it to print short versions of names: 
   	#then keep these next lines uncommented
	
	
   	print "$title </a><br>\n";
   } 

   if ($SMBURL ne NULL) {
	print "SAMBA : <a href=\"$SMBADDRESS$title\">${1}</a><br>\n";
   }
}

print "</BODY></HTML>\n";
