#!/usr/bin/perl -w
#**********************************************************************
# lptracks - split and sort wave files into tracks
# Copyright (C) 2004-2007 - Cameron Morland
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#**********************************************************************
my ($wav, $artist, $album);
my (@tracks);
my ($conffile);
my ($channels) = '';
if (!@ARGV) {
print <) {
s/#.*//; # strip comments
if (m/^\s$/) { next; } # and blank lines
if (m/WAV\s*=\s*(.*)/) { $wav = $1; }
if (m/ALBUM\s*=\s*(.*)/) { $album = $1; }
if (m/ARTIST\s*=\s*(.*)/) { $artist = $1; }
if (m/TRACKS\s*=\s*(.*)/) { @tracks = split('::', $1); }
# whichever comes last has effect.
if (m/MONO/) { $channels = '--downmix'; }
if (m/STEREO/) { $channels = ''; }
}
print "Wav = $wav\n";
print "Artist = $artist\n";
print "Album = $album\n";
$ntracks = @tracks;
print "Seeking $ntracks tracks\n";
$allthere = 1;
$trackn = 1;
foreach $track (@tracks) {
$tn = sprintf("%02d", $trackn);
if (! (-e "$wav-$tn.wav")) {
$allthere = 0;
print "Missing $wav-$tn.wav\n";
last;
}
$trackn++;
}
if (! $allthere) {
print "Seeking $ntracks tracks\n";
`gramofindtracks -n $ntracks $wav.wav`;
print "Processing tracks\n";
`gramoprocess $wav.wav`;
}
(-e $artist) or
mkdir $artist or
die "Can't make artist directory: $!\n";
(-e "$artist/$album") or
mkdir "$artist/$album" or
die "Can't make album directory: $!\n";
$trackn = 1;
# append, so we can run twice, once for each side
open(M3U, ">>$artist-$album.m3u") or die "Can't open $artist-$album.m3u: $!\n";
foreach $track (@tracks) {
# format track name for use in filesystem
my $trackfile = $track;
$trackfile = lc($trackfile); # lowercase
$trackfile =~ s|["'/:; &(){}\[\]]|_|g; # "] remove funny chars.
$tracklabelstr = sprintf("%03d", $tracklabel);
$trackfile = "$artist/$album/$tracklabelstr$trackfile.ogg";
$track =~ s|\"|''|g; # also here to fix shell.
# track number with leading zero
my $tn = sprintf("%02d", $trackn);
print M3U "$trackfile\n";
my $command =
"oggenc $wav-$tn.wav " . # filename
"-q 8 " . # quality
"-t \"$track\" " .
"-a $artist " .
"-l $album " .
"$channels " .
"-o $trackfile"; # output file
print "[$command]\n";
`$command`;
$trackn++;
$tracklabel++;
}
close(M3U);
close(CONFFILE);
}