From 028dedf7cfc028298e55bf07ef7ed41461b0f706 Mon Sep 17 00:00:00 2001 From: Eric Gillespie Date: Sun, 6 Mar 2022 19:50:36 -0600 Subject: [PATCH 1/1] Account for two Qobuz oddities in flac2mp3. - 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 | 29 +++++++++++++++++++++++++- t/read_tags.t | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++- tags.pl | 27 +++++++++++++++++++++--- 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/t/disc_tags.t b/t/disc_tags.t index b37424e..0d12a0a 100644 --- a/t/disc_tags.t +++ b/t/disc_tags.t @@ -1,9 +1,10 @@ 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'); @@ -36,3 +37,29 @@ eq_or_diff [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/; diff --git a/t/read_tags.t b/t/read_tags.t index 42a640b..ff7a651 100644 --- a/t/read_tags.t +++ b/t/read_tags.t @@ -1,9 +1,10 @@ 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'); @@ -51,6 +52,60 @@ eq_or_diff ], 'track ARTIST overrides album ARTIST'; +$fh = str_file_handle(< ['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(<) { 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)) { @@ -174,7 +182,20 @@ sub disc_tags { 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 -- 2.56.0