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
--- /dev/null
+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';
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
$tag
}
+=over
+
+=item B<disc_tags>
+
+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 {
"'$s'"
}
+=back
+
+=cut
+
1;