]> diplodocus.org Git - flac-archive/commitdiff
Account for two Qobuz oddities in flac2mp3.
authorEric Gillespie <epg@pretzelnet.org>
Mon, 7 Mar 2022 01:50:36 +0000 (19:50 -0600)
committerEric Gillespie <epg@pretzelnet.org>
Mon, 7 Mar 2022 01:50:36 +0000 (19:50 -0600)
- DESCRIPTION has multiple lines.  My tag-processing is trash.
  Just hack it for now.

- DISCNUMBER appears on even single-disc works: ignore it.

t/disc_tags.t
t/read_tags.t
tags.pl

index b37424e..0d12a0a 100644 (file)
@@ -1,9 +1,10 @@
 use v5.12;
 use warnings;
 
 use v5.12;
 use warnings;
 
-use Test::Simple tests => 2;
+use Test::Simple tests => 4;
 
 use Test::Differences;
 
 use Test::Differences;
+use Test::Exception;
 
 require './tags.pl';
 epg::flac::archive::tags->import('disc_tags');
 
 require './tags.pl';
 epg::flac::archive::tags->import('disc_tags');
@@ -36,3 +37,29 @@ eq_or_diff
      [2],
     ],
     'second disc';
      [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/;
index 42a640b..ff7a651 100644 (file)
@@ -1,9 +1,10 @@
 use v5.12;
 use warnings;
 
 use v5.12;
 use warnings;
 
-use Test::Simple tests => 3;
+use Test::Simple tests => 4;
 
 use Test::Differences;
 
 use Test::Differences;
+use Test::Exception;
 
 require './tags.pl';
 epg::flac::archive::tags->import('read_tags');
 
 require './tags.pl';
 epg::flac::archive::tags->import('read_tags');
@@ -51,6 +52,60 @@ eq_or_diff
     ],
     'track ARTIST overrides album ARTIST';
 
     ],
     '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 {
 exit;
 
 sub str_file_handle {
diff --git a/tags.pl b/tags.pl
index 71e6968..301b1dd 100644 (file)
--- a/tags.pl
+++ b/tags.pl
@@ -84,10 +84,18 @@ sub read_tags {
     my %album;
     my @tracks;
     my $tracknum = 0;
     my %album;
     my @tracks;
     my $tracknum = 0;
+    my $name;
     while (<$fh>) {
         chomp;
     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)) {
         # TODO validate $name
         # TODO album tags should be illegal after track tags
         if (defined($3)) {
@@ -174,7 +182,20 @@ sub disc_tags {
         if (@{$tags{DISCNUMBER}} != 1) {
             die('one or zero DISCNUMBER tags required')
         }
         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
     }
 
     $artist, $album_tag, $date, \@discnumber