#!/usr/local/bin/perl -w
#
# Script to create an index file for all these funny mp3s in here.
# Created at the secret-wg office...
# Copyright.. ah.. forget it.. copy whatever you want..
use strict;
my $mp3file;
my %by_artist;
my $key;

use MP3::Info;
if (! opendir (DOMAINDIR,"./")){
    print "Could not open ./";
    exit;
}



foreach $mp3file (sort (readdir DOMAINDIR)){
    no utf8;
    next if -d $mp3file;
    next if $mp3file !~ /mp3$/;
    my $mp3=MP3::Info->new($mp3file);
    my $filename=$mp3file;
    $filename =~ s/ /%20/g;
    my $title=$mp3->{"TITLE"};
    if (!$title ){
      $title=$mp3file;
      $title =~ s/\.mp3$//;
    }
    
    $by_artist{$mp3->{"ARTIST"}}.= "<li><A HREF=\"".$filename."\"> ".      #$mp3->{"ARTIST"} .": ".
    $title."</A> ".$mp3->{"ALBUM"}." (".$mp3file.") </li>\n"	;
}


header();

foreach $key (sort keys %by_artist ){
  print "<h3> $key </h3>\n<ul>";
  
  print $by_artist{$key};
  print "</ul>\n";
  
}  

footer();



sub header {
 print <<ENDHEADER;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
		<meta name="generator" content="Adobe GoLive 6">
		<title>Ernie...</title>
		<link href="./mp3.css" rel="stylesheet" media="screen">
	</head>

	<body bgcolor="#ffffff">
<h1>My MP3 Repository</H1>

This page is for my personal use. Do not spread the URL if you happen
to stumble on this page. 

<h2>Currently available</h2>

ENDHEADER
}


sub footer{
 print <<ENDFOOTER;

<hr>
Page created using <A href="mk-index.pl">this script</A>. Simple ain't it...
</body>
</html>

ENDFOOTER
#'


}
