- verbose("Running flac\n");
- $status = system('flac', '-o', "../$artist/$album.flac-tmp",
- '--delete-input-file', '-V', '--cuesheet',
- 'cue', '--no-padding', '--best',
- map({ ('-T', $_) } @tags),
- 'wav');
- if (WIFEXITED($status) and ($status = WEXITSTATUS($status)) != 0) {
- die("flac: $status");
- } elsif (WIFSIGNALED($status)) {
- die("flac killed with signal ", WTERMSIG($status));
- } elsif (WIFSTOPPED($status)) {
- die("flac stopped with signal ", WSTOPSIG($status));
+ my @artist;
+ my %things;
+ my (@bork, @titles);
+ for my $tag (@tags) {
+ if ($tag =~ /^([^[]+)\[(\d+)]=(.*)/) {
+ hhlp(\%things, $2, $1, $3);
+ } elsif ($tag =~ /^ARTIST=/) {
+ push(@artist, $tag);
+ } else {
+ push(@bork, $tag);
+ }
+ }
+ @tags = @bork;
+
+ my @files;
+ for my $tracknum (sort(map(int, keys(%things)))) {
+ my $title = join(' ', map(split, @{$things{$tracknum}->{'TITLE'}}));
+ $title =~ s|/|_|g;
+ $outfile = join(' ',
+ (defined($discnum)
+ ? sprintf('%02d', $discnum)
+ : ()),
+ sprintf('%02d', $tracknum),
+ $title);
+ push(@files, "$outdir/$outfile.flac");
+ $outfile = "../$outdir/$outfile";
+
+ my @lartist;
+ if (exists($things{$tracknum}->{'ARTIST'})) {
+ @lartist = ();
+ } else {
+ @lartist = @artist;
+ }
+
+ verbose("Running flac\n");
+ $status = system('flac', '-o', "$outfile.flac-tmp",
+ '--delete-input-file', '-V', '--no-padding', '--best',
+ map({ ('-T', $_) }
+ @lartist,
+ grep({ $_ !~ /^ARTIST=/ } @tags),
+ bork_tags($things{$tracknum})),
+ sprintf('track%02d.cdda.wav', $tracknum));
+ if (WIFEXITED($status)) {
+ if (($status = WEXITSTATUS($status)) != 0) {
+ die("flac exited with status $status");
+ }
+ } elsif (WIFSIGNALED($status)) {
+ die("flac killed with signal ", WTERMSIG($status));
+ } elsif (WIFSTOPPED($status)) {
+ die("flac stopped with signal ", WSTOPSIG($status));
+ } else {
+ die("Major horkage on system(flac): \$? = $? \$! = $!");
+ }
+
+ rename("$outfile.flac-tmp", "$outfile.flac")
+ or die("rename($outfile.flac-tmp, $outfile.flac): $!");