- 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));
+ 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);
+ }
+ }
+ @tags = @tmp;
+
+ for my $tracknum (sort(map(int, keys(%tracks_to_tags)))) {
+ my $title = join(' ', map(split, @{$tracks_to_tags{$tracknum}->{'TITLE'}}));
+ $title =~ s|/|_|g;
+ $outfile = join('/',
+ $outdir,
+ join(' ',
+ (defined($discnum)
+ ? sprintf('%02d', $discnum)
+ : ()),
+ sprintf('%02d', $tracknum),
+ $title));
+
+ # If we have ARTIST[n] tags for this track, set
+ # @track_artist to the empty list; they will go in along
+ # with the other [n] tags.
+ my @track_artist;
+ if (exists($tracks_to_tags{$tracknum}->{'ARTIST'})) {
+ @track_artist = ();
+ } else {
+ @track_artist = @disc_artist;
+ }
+
+ run_flac(sprintf('track%02d.cdda.wav', $tracknum), undef,
+ "../$outfile",
+ @track_artist,
+ @tags,
+ "TRACKNUMBER=$tracknum",
+ track_tags($tracks_to_tags{$tracknum}));
+ push(@files, "$outfile.flac");
+ }
+ $outlog = "../$outdir/log";