#!/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
# Customized by Jason Grider, jgrider@fiskars.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="/ntshare/music/";

# 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 
# Set it to '1' if you are using a HTTP URL
$URL=NULL;
$WEBADDRESS="http://localhost/";

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


# Root URL for Samba ie. \\goldfish\ if goldfish is your machine's name
# Please note that to obtain a \ in perl you must use \\, as perl ignores or takes literaly
# the next charicter after a \, hence \\\\smbservername\\share = \\smbservername\share.
$SMBADDRESS="\\\\fiskarspinguin\\music\$\\";

# 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="/ntshare/music/";

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

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

#Commands.  Find and Date at the moment

$command="find $filepath -iname '$filetype'";
@names = `$command`;
$command1="date '+%A %b %d %Y %T'";
@time = `$command1`;

#HTML Generation

print "<HTML><HEAD><TITLE>FiskarsPinguin MP3s</TITLE>\n";
print "<style type=\"text/css\">\n";
print "p.1 {font-family: \"lucida console\"\;font-size: 18px}\n";
print "p.2 {font-family: \"Arial\"\;font-size: 15px}\n";
print "p.3 {font-family: \"Tahoma\";font-size: 12px}\n";
print "</style></HEAD><BODY BGCOLOR=\"$body_bg_colour\"><BODY LINK=\"white\">\n";

print "<p><center><img src=\"/images/common/fiskarspinguin.gif\" width=180 height= 180></center></p>\n";
print "<p class=2>Listing of mp3s from <b>$SMBADDRESS</b><br>Last Updated: @time</p>\n";
print "<blockquote><p class=1>\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 "<a href=\"$SMBADDRESS$myline\">$title</a><br>\n";
   }
}

print "</blockquote></p>\n";
print "<p class=3> This page brought to you by <a href=\"http://www.perl.com\">Perl</a> and <a href=\"http://www.w3.org/MarkUp/\">HTML</a></p>\n";
print "</BODY></HTML>\n";
