]>
diplodocus.org Git - flac-archive/blob - fa-encode
5 B<fa-encode> - encode WAV files to FLAC
9 B<fa-encode> [B<-d> I<artist-directory>] B<input-directory>
11 I<artist-directory> defaults to the album B<ARTIST> in the tags file; one of
18 # POSIX.1-2017, Base Definitions, 3.282 Portable Filename Character Set says
20 # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282
22 # Flac tags (set with `flac -T fieldname=...`) are Vorbis comments.
23 # https://www.xiph.org/vorbis/doc/v-comment.html#fieldnames field names we care about:
24 # - TITLE - Track/Work name
25 # - VERSION - may be used to differentiate multiple versions of the same track title in a single collection. (e.g. remix info)
26 # - ALBUM - The collection name to which this track belongs
27 # - TRACKNUMBER - The track number of this piece
28 # - ARTIST - The artist generally considered responsible for the track
29 # - DATE - Date the track was recorded (XXX I use US release date)
30 # https://age.hobba.nl/audio/mirroredpages/ogg-tagging.html (supposedly mirrored from http://reactor-core.org/ogg-tagging.html )
32 # - DISCNUMBER - if part of a multi-disc album, put the disc number here
33 # - VERSION - e.g. "live", "radio edit"
34 # - PARTNUMBER - part number if a work is divided across tracks
35 # - PART - part name e.g. "Oh sole mio"
36 # https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html
37 # - ALBUMARTIST - maps to ID3v2 TPE2
39 # Input is a directory containing:
40 # - trackNN.cdda.wav - WAV format files ripped from CD-DA audio tracks where NN is track number 01 - 99
41 # - tags - described below
42 # - cover.front.jpeg - optional JPEG format file containing the album front cover
44 # The tags file is composed of two blocks:
51 # - DISCNUMBER (optional)
53 # Track tags may be any of the rest of the tags listed above, suffixed with
54 # [N] where N is the track number. ARTIST, and only ARTIST, may also appear
55 # in the track tags. In this case, it overrides the album artist. In order
56 # to add artists, the album artist must be listed again. For example, Reba
57 # McEntire's "The Heart Won't Lie" on the album "It's Your Call" features
58 # Vince Gill, and is specified as:
59 # ARTIST=Reba McEntire
60 # ALBUM=It's Your Call
61 # TITLE[5]=The Heart Won't Lie
62 # ARTIST[5]=Reba McEntire
63 # ARTIST[5]=Vince Gill
65 package epg
::flac
::archive
::encode
;
72 require "$FindBin::Bin/tags.p";
73 epg
::flac
::archive
::tags-
>import(
81 my $input_directory = shift;
82 my $fn = "$input_directory/tags";
83 open(my $fh, '<', $fn) || die("open($fn): $!");
84 my ($album, $tracks) = read_tags
($fh);
85 if (!defined($album->{ALBUM
}) || scalar(@{$album->{ALBUM
}}) != 1) {
86 die('exactly one ALBUM tag required')
88 my $album_tag = $album->{ALBUM
}->[0];
90 if (!defined($album->{ARTIST
}) || scalar(@{$album->{ARTIST
}}) != 1) {
91 die('exactly one ARTIST tag required')
93 my $artist = $album->{ARTIST
}->[0];
96 if (defined($album->{DATE
})) {
97 if (scalar(@{$album->{DATE
}}) != 1) {
98 die('one or zero DATE tags required')
100 $date = $album->{DATE
}->[0];
103 if (defined($album->{DISCNUMBER
})) {
104 if (scalar(@{$album->{DISCNUMBER
}}) != 1) {
105 die('one or zero DISCNUMBER tags required')
107 @discnumber = ($album->{DISCNUMBER
}->[0]);
110 my $dir = join('/', '..', mangle_for_file_name
($artist), mangle_for_file_name
($album_tag));
113 say('mkdir -p ', quote
($dir));
115 for my $track (@$tracks) {
117 if (!defined($track->{TITLE
}) || scalar(@{$track->{TITLE
}}) < 1) {
118 die("at least one TITLE required for track $tracknum")
120 $track->{ALBUM
} = $album->{ALBUM
};
121 $track->{TRACKNUMBER
} = [$tracknum];
122 if (!defined($track->{ARTIST
}) && defined($album->{ARTIST
})) {
123 $track->{ARTIST
} = $album->{ARTIST
};
125 if (defined($date)) {
126 $track->{DATE
} = [$date];
129 $track->{DISCNUMBER
} = \
@discnumber;
131 my $title = join(' ', @{$track->{TITLE
}});
132 my $tracknum_s = sprintf('%02d', $tracknum);
136 (map { sprintf('%02d', $_) } @discnumber),
138 mangle_for_file_name
($title) . '.flac',
141 -e
$fn && die("cowardly refusing to clobber $fn");
142 my @pictures = ('--picture', quote
('3|image/jpeg|||cover.front.jpeg')); # TODO optional
146 '--delete-input-file',
154 ('-T', quote
($name . '=' . $_))
156 } sort(keys(%$track))),
157 "track$tracknum_s.cdda.wav"
160 say('rm tags cover.front.jpeg');