# Sample format for mp3index # # This wil generate a nice HTML table with quick jumps to go to a # specific artist on the first output file and a simple (and often # unreadable) tab-delimited listing on the second output file. # # **IMPORTANT** If you want to have an @ sign, such as in an # email address, you _MUST_ prefix it with a \ unless the # string which the @ appears in is surrounded by 'single quotes'. # If it is part of a here document (print < # formatfile Format file customized by Richard van den Berg # format 1 desc Generates a nice HTML table of everything arranged by artist with anchors and links to jump to a certain artist. If you generate all three output files at the same time, provides links to the other output files. # format 1 options Your email address^(optional) HTML for page^(optional) Header (in <H1> tags) for page^(Only if the output files are going to different directories) Prefix to add to the link to the first output file so that the second and third can get to it (use your webserver's paths, not your filesystems)^Path to second output (see option 4)^Path to third output (see option 4) # format 2 desc Generates a nice HTML table of everything arranged by song length. If you generate all three output files at the same time, provides links to the other output files. # format 2 options Your email address^(optional) HTML <title> for page^(optional) Header (in <H1> tags) for page^(Only if the output files are going to different directories) Prefix to add to the link to the first output file so that the second and third can get to it (use your webserver's paths, not your filesystems)^Path to second output (see option 4)^Path to third output (see option 4) # format 3 desc Generates a nice HTML table of everything arranged by song title with anchors and links to jump to titles starting with a certain letter. If you generate all three output files at the same time, provides links to the other output files. # format 3 options Your email address^(optional) HTML <title> for page^(optional) Header (in <H1> tags) for page^(Only if the output files are going to different directories) Prefix to add to the link to the first output file so that the second and third can get to it (use your webserver's paths, not your filesystems)^Path to second output (see option 4)^Path to third output (see option 4) # format 4 desc Generates a nice HTML table of everything arranged by album with anchors and links to jump to titles starting with a certain letter. If you generate all three output files at the same time, provides links to the other output files. # format 4 options Your email address^(optional) HTML <title> for page^(optional) Header (in <H1> tags) for page^(Only if the output files are going to different directories) Prefix to add to the link to the first output file so that the second and third can get to it (use your webserver's paths, not your filesystems)^Path to second output (see option 4)^Path to third output (see option 4) # format 5 desc Generates a nice HTML table of everything arranged by year with anchors and links to jump to titles starting with a certain letter. If you generate all three output files at the same time, provides links to the other output files. # format 5 options Your email address^(optional) HTML <title> for page^(optional) Header (in <H1> tags) for page^(Only if the output files are going to different directories) Prefix to add to the link to the first output file so that the second and third can get to it (use your webserver's paths, not your filesystems)^Path to second output (see option 4)^Path to third output (see option 4) $noopen = 0; #If a format file sets this to one, the output files won't be open $bodyonly = 0; #If a format file sets this to one, the head and body subs won't be called $passlist = 0; #If a format file sets this to one, the body sub will be called once and @list will be set to a list of hashrefs. #The hashrefs will have the following keys: #artist, title, ftpurl, httpurl, playurl #bitrate, length, size, album, year, comment, genre #prettysize, prettylongsize, data [array ref] # #ftpurl, httpurl, and playurl may not be present $adlines=20; # Insert an ad every this many lines $adline=0; # Counter to keep track of how many lines ago the ad started $clickurl="http://www.mp3index.net/cgi/download/mp3"; sub outhead { #This is the header for all output files. The second and third #output files just change some variables and call this. #If the arguments you pass to mp3index include something like this: # #--options="foo@bar.com^Title for my MP3 files by artist^H1 for my MP3 #files by artist" --options="foo@bar.com^Title for my MP3 files by #length^H1 for my MP3 files by length" --options="foo@bar.com^Title^H1" # #then $options[1] and $options[2] will be set appropriately, depending #on what output file we're writing to. # #Oh, and $options[0] is your email address btw. #Reset counter for ads $adline=0; $title = $options[1] || "Richard's MP3 collection"; $head = $options[2] || "Richard's MP3 collection"; #What you are about to see is a "here document." It prints everything #until EOF by itself as if it were enclosed in double quotes (ie: $var #will print the value of $var.) It also prints the newlines. #Print the basic headers. print <<EOF <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <HTML> <HEAD> <TITLE>$title

$head


This collection of MPEG audio contains ${totalhours}h ${totalmins}m ${totalsecs}s of music totalling $prettylongtotalsize.

Google
 
Web mp3index.net

EOF ; print "Click here to play them all!
\n" if $playall_url; if($playall_url or %playurl) { print 'For instructions on configuring Netscape to work with these'; print ' playing links, go '; print ''; print "here.

\n"; } #If we're not writing to three output files (ie: we're only writing to #one or we're using mp3index > outfile, we don't want to include the #links to the second and third output file. If you only want to use #two output files, you'll need to hack this a bit. # #If your output files are in different directories, $options[3,4,5] #should contain the prefixes you want attached to the links for artist, #length, and title. @xoutfile = @OUTFILE; #Strip /leading/paths from filenames. $xoutfile[0] =~ s!.+/(.+)!$1!; $xoutfile[1] =~ s!.+/(.+)!$1!; $xoutfile[2] =~ s!.+/(.+)!$1!; # $xoutfile[3] =~ s!.+/(.+)!$1!; # $xoutfile[4] =~ s!.+/(.+)!$1!; $options[3] ||= ""; $options[4] ||= ""; $options[5] ||= ""; # $options[6] ||= ""; # $options[7] ||= ""; $options[3] =~ s!(.+)[^/]^!$1/!; #add trailing slash if needed $options[4] =~ s!(.+)[^/]^!$1/!; #add trailing slash if needed $options[5] =~ s!(.+)[^/]^!$1/!; #add trailing slash if needed # $options[6] =~ s!(.+)[^/]^!$1/!; #add trailing slash if needed # $options[7] =~ s!(.+)[^/]^!$1/!; #add trailing slash if needed # if($OUTFILE[0] && $OUTFILE[1] && $OUTFILE[2] && $OUTFILE[3] && $OUTFILE[4]) { if($OUTFILE[0] && $OUTFILE[1] && $OUTFILE[2]) { print ""; print ""; # print ""; print ""; print ""; # print ""; print "
Sorted by ArtistSorted by LengthSorted by TitleSorted by AlbumSorted by Year
\n"; } #print jumps to specific artists\first letters of titles print '


'; if(!(defined $sortmode)) { print "Jump to a certain artist
\n"; } elsif($sortmode eq "title") { print "Jump to a title by initial letter
\n"; } elsif($sortmode eq "album") { print "Jump to a album by initial letter
\n"; } $prevartist = ""; if (!(defined $sortmode)) { foreach $artist(sort values %artist) { if($artist ne $prevartist) { #a new artist $prevartist = $artist; print "$artist
\n"; } } } elsif ($sortmode eq "title") { foreach $ctitle(sort values %title) { $xtitle = substr(uc($ctitle), 0, 1); if($xtitle ne $prevartist) { #a new first letter $prevartist = $xtitle; print "$xtitle
\n"; } } } elsif ($sortmode eq "album") { foreach $calbum(sort values %album) { $xalbum = substr(uc($calbum), 0, 1); if($xalbum ne $prevartist) { #a new first letter $prevartist = $xalbum; print "$xalbum
\n"; } } } $prevartist = ""; #The actual headers for the table print < EOF ; print '' if %ftpurl; print '' if %httpurl; print '' if %playurl; print ''; print '' if $MPEG::MP3Info::VERSION > 0.71; print ""; print "\n"; } sub outbody { #The body print '" if %ftpurl; print "" if %httpurl; print "" if %playurl; print ""; if($MPEG::MP3Info::VERSION > 0.71) { if($vbr){ print ""; } else { print ""; } } print ""; # Insert ad if needed if(!$adline || $adline >= $adlines) { print ""; $adline=0; } print "\n"; ++$adline; } sub outfoot { #The footer $email = $options[0] || 'you_should_put_your_email_address_as_the_first_option_in_--options_for_each_output_file@foo.bar'; print "" if $notfirst; #Fill table with empty lines to space out left over ad space for($i=0;$i+$adline<$adlines;$i++){ print "\n"; } $now=localtime(time()); print <
Generated at $now

Jump to MP3 collection home

$email
EOF ; } #sub outhead2 { #For the second and third output files, we set $sortmode & $mp3 # @mp3 = sort { $length{$a} cmp $length{$b} } @mp3; # $sortmode = "none"; # &outhead; #} #sub outbody2 { &outbody; } #sub outfoot2 { &outfoot; } sub outhead2 { @mp3 = sort { $title{$a} cmp $title{$b} } @mp3; $sortmode = "title"; &outhead; } sub outbody2 { &outbody; } sub outfoot2 { &outfoot; } sub outhead3 { @mp3 = sort { $album{$a} cmp $album{$b} } @mp3; $sortmode = "album"; &outhead; } sub outbody3 { &outbody; } sub outfoot3 { &outfoot; } #sub outhead5 { # @mp3 = sort { $year{$a} <=> $year{$b} } @mp3; # $sortmode = "year"; # &outhead; #} #sub outbody5 { &outbody; } #sub outfoot5 { &outfoot; }
Artist - TitleFTP (Preferred)HTTPPlay it!Song LengthFile SizeBitrateVBR?AlbumYear
'; #Print the anchors for jumps print "\n"; print "$artist - $title"; if ($mustclose) { print "" ; $mustclose = 0; } print "Get it (FTP)Get it (HTTP)Play it!$length$prettysize$bitrate
vbrcbr$album$year\n"; # print "\n"; print "