#!/usr/bin/perl
#
# Create the stored music lists
#
# $Id: mklist,v 1.6 2002/05/26 17:43:34 dds Exp $
#
# Use -t option to create a track listing
#
# (C) Copyright 2000-2002 Diomidis Spinellis
#
# Permission to use, copy, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation.
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
open(PLAYLIST, '>/vol/db/playlist') || die;
open(HTML, '>/vol/db/playlist.html') || die;
open(TEX, '>/vol/db/playlist.tex') || die;
htmlhead();
texhead();
# Process bookmarks
htmlcontents("Bookmarks", 1);
$html .= "
\n";
print TEX '
\section{Bookmarks}
\begin{tabular}{rl}
';
open(FILE, 'find /vol/db/bookmarks -type f -print | sort |') || die "find: $!\n"; ;
while () {
chop;
$name = $fname = $_;
$name =~ s,.*/,,;
open(BK, $fname);
while () {
chop;
next if (/^#/);
$num = $1 if (/^NU (\d+)/);
$bk = $1 if (/^BK (\d+)/);
}
close(BK);
$name = fix($fname);
$html .= "- $num
- $name\n";
print TEX "{\\em $num} & $name \\\\\n";
$bookmark{$bk} = $num;
}
$html .= "
\n";
print TEX "\\end{tabular}\n";
# Process index files and create full track list
htmlcontents("Disks", 1);
print TEX "\\section{Disks}\n";
open(FILE, 'find /vol/music -name index.txt -print | sort |') || die;
while () {
chop;
$dir = $idxname = $_;
$dir =~ s,/index.txt$,,;
open(IDX, $idxname) || die;
while () {
chop;
next if (/^#/);
if (/^DN (.*)/) {
$dn = $1;
pathheader($dir, $dn, 1, "#DN$dn");
print PLAYLIST "# $dn\n";
print PLAYLIST "# $b\n" if ($b = $bookmark{$dn});
}
if (/^TN (\d+)\001(.*)/) {
print PLAYLIST "# $b\n" if ($b = $bookmark{$1});
print PLAYLIST "# $1\n$dir/$2\n";
}
}
close(IDX);
}
# Process collections
if ($ARGV[0] eq '-t') {
# Process tracks
htmlcontents("Tracks", 1);
print TEX "\\section{Tracks}\n";
open(FILE, 'find /vol/music -name index.txt -print | sort |') || die;
while () {
chop;
$dir = $idxname = $_;
$dir =~ s,/index.txt$,,;
# Try to read track info from info.txt
undef %trackname;
if (open(INFO, $q = "$dir/info.txt")) {
while () {
chop;
if (/^TR (.*)/) {
($tn, $infoname, $fname) = split(/\001/);
$trackname{$fname} = $infoname;
}
}
close(INFO);
}
open(IDX, $idxname) || die;
while () {
chop;
next if (/^#/);
if (/^DN (.*)/) {
$html .= " ";
}
if (/^TN (\d+)\001(.*)/) {
$tracknum = $1;
$trackfname = $2;
if (defined($trackname{$trackfname})) {
$trackname = $trackname{$trackfname};
} else {
$id3 = id3name("$dir/$trackfname");
$tryname = $trackfname;
$tryname =~ s/track-?//i;
$simplename = fix($tryname);
$trackname = (length($id3) > length($simplename)) ? $id3 : $simplename;
}
$trackname =~ s,/,:,g; # Not to confuse pathheader
# URL in Windows format
pathheader("$dir/$trackname", $tracknum, 0, "file:////spiti/$dir/$fname");
}
}
close(IDX);
}
} # process tracks
$html .= "