- DESCRIPTION has multiple lines. My tag-processing is trash.
Just hack it for now.
- DISCNUMBER appears on even single-disc works: ignore it.
use v5.12;
use warnings;
-use Test::Simple tests => 2;
+use Test::Simple tests => 4;
use Test::Differences;
+use Test::Exception;
require './tags.pl';
epg::flac::archive::tags->import('disc_tags');
[2],
],
'second disc';
+
+eq_or_diff
+ [disc_tags(
+ ARTIST => ['Kim Wilde'],
+ ALBUM => ['Close'],
+ DISCNUMBER => [1],
+ DISCTOTAL => [1],
+ )],
+ [
+ 'Kim Wilde',
+ 'Close',
+ undef,
+ [],
+ ],
+ 'extraneous DISCNUMBER tag with DISCTOTAL=1 ignored';
+
+# broken data
+
+throws_ok { disc_tags(
+ ARTIST => ['Nine Inch Nails'],
+ ALBUM => ['Broken'],
+ DISCNUMBER => [5],
+ DISCTOTAL => [1],
+ ),
+}
+qr/DISCNUMBER=5 > DISCTOTAL=1/;
use v5.12;
use warnings;
-use Test::Simple tests => 3;
+use Test::Simple tests => 4;
use Test::Differences;
+use Test::Exception;
require './tags.pl';
epg::flac::archive::tags->import('read_tags');
],
'track ARTIST overrides album ARTIST';
+$fh = str_file_handle(<<EOF);
+ALBUM=Close
+TITLE=You Came
+TRACKNUMBER=2
+TRACKTOTAL=10
+DISCNUMBER=1
+DISCTOTAL=1
+DATE=1988
+GROUPING=Pop
+COPYRIGHT=℗ 1988 MCA Records Ltd.
+GENRE=Pop Rock
+ALBUMARTIST=Kim Wilde
+ARTIST=Kim Wilde
+DESCRIPTION=Interprètes : Tony Swain, Producer
+Kim Wilde, Vocals, MainArtist, AssociatedPerformer, ComposerLyricist
+Rick Wilde, ComposerLyricist
+Ricki Wilde, Producer\r
+Label : UMC (Universal Music Catalogue) - Universal Music\r
+
+EOF
+eq_or_diff
+ [read_tags($fh)],
+ [
+ {
+ ARTIST => ['Kim Wilde'],
+ ALBUM => ['Close'],
+ DISCNUMBER => ['1'],
+ DISCTOTAL => ['1'],
+ DATE => ['1988'],
+ GROUPING => ['Pop'],
+ COPYRIGHT => ['℗ 1988 MCA Records Ltd.'],
+ GENRE => ['Pop Rock'],
+ ALBUMARTIST => ['Kim Wilde'],
+ ARTIST => ['Kim Wilde'],
+ DESCRIPTION => ['Interprètes : Tony Swain, Producer'],
+ TITLE => ['You Came'],
+ TRACKNUMBER => ['2'],
+ TRACKTOTAL => ['10'],
+ },
+ [],
+ ],
+ 'multiple lines in tag';
+
+# broken data
+
+$fh = str_file_handle(<<EOF);
+lead off with junk
+EOF
+
+$fh = str_file_handle(<<EOF);
+ARTIST=Reba McEntire
+starteed off good but went bad...
+EOF
+
exit;
sub str_file_handle {
my %album;
my @tracks;
my $tracknum = 0;
+ my $name;
while (<$fh>) {
chomp;
- s/^([^=[\]]+)(\[(\d+)])?=// || die("no field name in $_");
- my $name = $1;
+ if (!s/^([^=[\]]+)(\[(\d+)])?=//) {
+ if (defined($name) && $name eq 'DESCRIPTION') {
+ # Qobuz offers FLAC files like this.
+ warn("looks like DESCRIPTION had multiple lines; discarding and returning early: $_");
+ last
+ }
+ die("no field name in $_");
+ }
+ $name = $1;
# TODO validate $name
# TODO album tags should be illegal after track tags
if (defined($3)) {
if (@{$tags{DISCNUMBER}} != 1) {
die('one or zero DISCNUMBER tags required')
}
- @discnumber = ($tags{DISCNUMBER}->[0]);
+ my ($discnum) = @{$tags{DISCNUMBER}};
+ @discnumber = ($discnum);
+ # But check it against DISCTOTAL if present.
+ my $total = $tags{DISCTOTAL};
+ if (defined($total) && @$total > 0) {
+ my ($total) = @$total;
+ if ($total < $discnum) {
+ die("DISCNUMBER=$discnum > DISCTOTAL=$total")
+ }
+ if ($total == 1) {
+ # Qobuz offers FLAC files like this.
+ @discnumber = ();
+ }
+ }
}
$artist, $album_tag, $date, \@discnumber