]);
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 {
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");
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';
use v5.12;
use warnings;
-use Test::Simple tests => 6;
+use Test::Simple tests => 7;
use Test::Differences;
use Test::Exception;
],
'multiple lines in tag';
+$fh = str_file_handle(<<EOF);
+ARTIST=Marillion
+ALBUM=An Hour Before It's Dark
+DATE=2022-03-04
+TITLE[1]=Care
+PART[1]=IV. Angels On Earth
+PARTNUMBER[1]=4
+TITLE[2]=(silence)
+TITLE[3]=Murder Machines
+VERSION[3]=12 inch remix
+EOF
+eq_or_diff
+ [read_tags($fh)],
+ [
+ {
+ ARTIST => ['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(<<EOF);