From fee6350f22d80d9f54f9ad4dccbfa7696e3e861a Mon Sep 17 00:00:00 2001 From: Eric Gillespie Date: Sun, 6 Mar 2022 18:56:44 -0600 Subject: [PATCH 1/1] tidy and test epg::flac::archive::tags::disc_tags --- flac2mp3 | 2 +- t/disc_tags.t | 38 ++++++++++++++++++++++++++++++++ tags.pl | 60 ++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 t/disc_tags.t diff --git a/flac2mp3 b/flac2mp3 index b4126e2..d82e61d 100755 --- a/flac2mp3 +++ b/flac2mp3 @@ -68,7 +68,7 @@ epg::flac::archive::tags->import( sub flac2mp3 { my $quoted_flac = quote(shift); my $tags = shift; - my ($album, $artist, $date, $discnumber) = disc_tags($tags); + my ($artist, $album, $date, $discnumber) = disc_tags(%$tags); # TODO resurrect whole-disc FLAC? # Stupid hack: only a single-track file should have the diff --git a/t/disc_tags.t b/t/disc_tags.t new file mode 100644 index 0000000..b37424e --- /dev/null +++ b/t/disc_tags.t @@ -0,0 +1,38 @@ +use v5.12; +use warnings; + +use Test::Simple tests => 2; + +use Test::Differences; + +require './tags.pl'; +epg::flac::archive::tags->import('disc_tags'); + +eq_or_diff + [disc_tags( + ARTIST => ['Fates Warning'], + ALBUM => ['The Spectre Within'], + DATE => [1985], + )], + [ + 'Fates Warning', + 'The Spectre Within', + '1985', + [], + ], + 'single disc'; + +eq_or_diff + [disc_tags( + ARTIST => ['Depeche Mode'], + ALBUM => [101], + DATE => ['1989-03-14'], + DISCNUMBER => [2], + )], + [ + 'Depeche Mode', + '101', + '1989-03-14', + [2], + ], + 'second disc'; diff --git a/tags.pl b/tags.pl index 2df6458..71e6968 100644 --- a/tags.pl +++ b/tags.pl @@ -1,5 +1,15 @@ package epg::flac::archive::tags; +=head1 NAME tags.pl + +subroutines for tag processing + +=head1 DESCRIPTION + +TODO + +=cut + # POSIX.1-2017, Base Definitions, 3.282 Portable Filename Character Set says # [A-Za-z0-9._-] # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282 @@ -115,37 +125,59 @@ sub one { $tag } +=over + +=item B + +Interpret the tags hash for a disc, returning: + +=over + +=item * +Artist tag (exactly one required in the hash). + +=item * +Album tag (exactly one required). + +=item * +Date tag (zero or one required). + +=item * +Disc number (zero or one required) as a reference to an array of size 0 or 1. + +=back +=cut sub disc_tags { - my $album = shift; + my %tags = @_; - if (!defined($album->{ALBUM}) || @{$album->{ALBUM}} != 1) { + if (!defined($tags{ALBUM}) || @{$tags{ALBUM}} != 1) { die('exactly one ALBUM tag required') } - my $album_tag = $album->{ALBUM}->[0]; + my $album_tag = $tags{ALBUM}->[0]; # TODO ALBUMARTIST - if (!defined($album->{ARTIST}) || @{$album->{ARTIST}} != 1) { + if (!defined($tags{ARTIST}) || @{$tags{ARTIST}} != 1) { die('exactly one ARTIST tag required') } - my $artist = $album->{ARTIST}->[0]; + my $artist = $tags{ARTIST}->[0]; my $date; - if (defined($album->{DATE})) { - if (@{$album->{DATE}} != 1) { + if (defined($tags{DATE})) { + if (@{$tags{DATE}} != 1) { die('one or zero DATE tags required') } - $date = $album->{DATE}->[0]; + $date = $tags{DATE}->[0]; } my @discnumber = (); - if (defined($album->{DISCNUMBER})) { - if (@{$album->{DISCNUMBER}} != 1) { + if (defined($tags{DISCNUMBER})) { + if (@{$tags{DISCNUMBER}} != 1) { die('one or zero DISCNUMBER tags required') } - @discnumber = ($album->{DISCNUMBER}->[0]); + @discnumber = ($tags{DISCNUMBER}->[0]); } - $album_tag, $artist, $date, \@discnumber + $artist, $album_tag, $date, \@discnumber } sub mangle_for_file_name { @@ -166,4 +198,8 @@ sub quote { "'$s'" } +=back + +=cut + 1; -- 2.56.0