From: Eric Gillespie Date: Mon, 21 Mar 2022 01:59:50 +0000 (-0500) Subject: Test PARTNUMBER and VERSION. X-Git-Url: https://diplodocus.org/git/flac-archive/commitdiff_plain/ec1b0681479733956d68289f13357c95ae6cfcf1 Test PARTNUMBER and VERSION. --- diff --git a/fa-encode b/fa-encode index 10210b9..8a1dc63 100755 --- a/fa-encode +++ b/fa-encode @@ -35,15 +35,20 @@ epg::flac::archive::tags->import( ]); sub filename { - my %a = @_; - my @discnumber = @{$a{discnumber} // []}; - my $tracknumber = $a{tracknumber} // die('tracknumber required'); - my $title = $a{title} // die('title required'); + my ($tracknumber, $tags) = @_; + my $title = $tags->{TITLE} // die('title required'); + my @discnumber = @{$tags->{DISCNUMBER} // []}; + my @partnumber = @{$tags->{PARTNUMBER} // []}; + my @version = @{$tags->{VERSION} // []}; join('-', (map { two_digits($_) } @discnumber), two_digits($tracknumber), - mangle_for_file_name($title) . '.flac', + mangle_for_file_name(join('TODO multi-title?', @$title)), + # TODO more than one VERSION? + (map { mangle_for_file_name($_) } @version), + @partnumber, ) + . '.flac', } sub main { @@ -102,9 +107,8 @@ sub main { my $fn = join('/', $dir, filename( - discnumber => \@discnumber, - tracknumber => $tracknum, - title => $title, + $tracknum, + {track_tags_from_disc($album, $tracks, $tracknum)} ), ); -e $fn && die("cowardly refusing to clobber $fn"); diff --git a/t/encode.t b/t/encode.t index 06b7cea..574c648 100644 --- a/t/encode.t +++ b/t/encode.t @@ -1,25 +1,82 @@ use v5.12; use warnings; -use Test::More tests => 2; +use Test::More tests => 6; use FindBin; use lib "$FindBin::Bin/.."; require 'tags.pl'; +epg::flac::archive::tags->import('track_tags_from_disc'); require 'fa-encode'; -is - '02-03-the_title.flac', - epg::flac::archive::encode::filename( - discnumber => [2], - tracknumber => 3, - title => 'the title' +is epg::flac::archive::encode::filename( + 3, + { + DISCNUMBER => [2], + TITLE => ['the title'], + } ), + '02-03-the_title.flac', 'with discnumber'; is + epg::flac::archive::encode::filename(1, {TITLE => ['the title']}), '01-the_title.flac', - epg::flac::archive::encode::filename(tracknumber => 1, title => 'the title'), 'without discnumber'; + +my $album = { + ARTIST => ['Marillion'], + ALBUM => ["An Hour Before It's Dark"], + DATE => ['2022-03-04'], +}; +my $tracks = [ + { + TITLE => ['Care'], + PART => ['IV. Angels On Earth'], + PARTNUMBER => [4], + }, + { + TITLE => ['(silence)'], + }, + { + TITLE => ['Murder Machines'], + VERSION => ['12 inch remix'], + }, + { + TITLE => ['testing both and with leading 0'], + PARTNUMBER => ['04'], + VERSION => ['live'], + }, + { + TITLE => ['(silence)'], + }, + { + TITLE => ['Murder Machines'], + VERSION => ['12 inch remix'], + }, +]; +is epg::flac::archive::encode::filename( + 1, {epg::flac::archive::tags::track_tags_from_disc($album, $tracks, 1)}, + ), + '01-Care-4.flac', + 'PART goes into filename, PARTNUMBER ignored'; + +is epg::flac::archive::encode::filename( + 2, {epg::flac::archive::tags::track_tags_from_disc($album, $tracks, 2)}, + ), + '02-silence.flac', + 'parens in track title omitted'; + +is epg::flac::archive::encode::filename( + 3, {epg::flac::archive::tags::track_tags_from_disc($album, $tracks, 3)}, + ), + '03-Murder_Machines-12_inch_remix.flac', + 'VERSION goes into filename'; + +is epg::flac::archive::encode::filename( + 4, {epg::flac::archive::tags::track_tags_from_disc($album, $tracks, 4)}, + ), + '04-testing_both_and_with_leading_0-live-04.flac', + 'PARTNUMBER with leading 0 and VERSION'; diff --git a/t/read_tags.t b/t/read_tags.t index a694db5..a47b3d0 100644 --- a/t/read_tags.t +++ b/t/read_tags.t @@ -1,7 +1,7 @@ use v5.12; use warnings; -use Test::Simple tests => 6; +use Test::Simple tests => 7; use Test::Differences; use Test::Exception; @@ -95,6 +95,42 @@ eq_or_diff ], 'multiple lines in tag'; +$fh = str_file_handle(< ['Marillion'], + ALBUM => ["An Hour Before It's Dark"], + DATE=> ['2022-03-04'], + }, + [ + { + TITLE => ['Care'], + PART => ['IV. Angels On Earth'], + PARTNUMBER => [4], + }, + { + TITLE => ['(silence)'], + }, + { + TITLE => ['Murder Machines'], + VERSION => ['12 inch remix'], + }, + ], + ], + 'PART, PARTNUMBER, and VERSION'; + # broken data $fh = str_file_handle(<