- 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");
+ if ($single_file) {
+ $outfile = $album;
+ defined($discnum) and $outfile .= " (disc $discnum)";
+ run_flac('wav', 'cue', "../$artist/$outfile", @tags);
+ $outlog = "../$artist/$outfile.log";
+ @files = ("$artist/$outfile.flac");
+ } else {
+ # Go over @tags, store all [n] tags in a list keyed by n in
+ # %tracks_to_tags, store all ARTIST (not ARTIST[n]) tags in
+ # @disc_artist, and leave the rest in @tags.
+ my %tracks_to_tags;
+ my @disc_artist;
+ my @tmp;
+ for my $tag (@tags) {
+ if ($tag =~ /^([^[]+)\[(\d+)]=(.*)/) {
+ push(@{$tracks_to_tags{$2}->{$1}}, $3);
+ } elsif ($tag =~ /^ARTIST=/) {
+ push(@disc_artist, $tag);
+ } else {
+ push(@tmp, $tag);