X-Git-Url: https://diplodocus.org/git/flac-archive/blobdiff_plain/c3c2f3fcc2721a9c6cc9b7fc4127bdff56d233d4..42260d77bcf7b2293e9a06bf8ea849ad0c947ad6:/fa-flacd diff --git a/fa-flacd b/fa-flacd index f2e20b7..cdf48a0 100755 --- a/fa-flacd +++ b/fa-flacd @@ -65,7 +65,7 @@ sub get_tags { return ($artist, $album, $discnum, @tags); } -sub bork_tags { +sub track_tags { my $h = shift; my @result; @@ -151,45 +151,53 @@ sub flac { $outlog = "../$artist/$outfile.log"; @files = ("$artist/$outfile.flac"); } else { - my %things; - my @artist; - my @bork; + # 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(@{$things{$2}->{$1}}, $3); + push(@{$tracks_to_tags{$2}->{$1}}, $3); } elsif ($tag =~ /^ARTIST=/) { - push(@artist, $tag); + push(@disc_artist, $tag); } else { - push(@bork, $tag); + push(@tmp, $tag); } } - @tags = @bork; + @tags = @tmp; - for my $tracknum (sort(map(int, keys(%things)))) { - my $title = join(' ', map(split, @{$things{$tracknum}->{'TITLE'}})); + 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(' ', - (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 = (); + $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 { - @lartist = @artist; + @track_artist = @disc_artist; } - run_flac(sprintf('track%02d.cdda.wav', $tracknum), undef, $outfile, - @lartist, - grep({ $_ !~ /^ARTIST=/ } @tags), - bork_tags($things{$tracknum})); - $outlog = "../$outdir/log"; + run_flac(sprintf('track%02d.cdda.wav', $tracknum), undef, + "../$outfile", + @track_artist, + @tags, + track_tags($tracks_to_tags{$tracknum})); + push(@files, "$outfile.flac"); } + $outlog = "../$outdir/log"; } verbose("Cleaning up $dir\n");