]>
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 # I use one more, though I'm unsure where I got it. Did I make it up?
31 # - DISCNUMBER - number in multi-disc collection
33 # Input is a directory containing:
34 # - trackNN.cdda.wav - WAV format files ripped from CD-DA audio tracks where NN is track number 01 - 99
35 # - tags - described below
36 # - cover.front.jpeg - optional JPEG format file containing the album front cover
38 # The tags file is composed of two blocks:
45 # - DISCNUMBER (optional)
47 # Track tags may be any of the rest of the tags listed above, suffixed with
48 # [N] where N is the track number. ARTIST, and only ARTIST, may also appear
49 # in the track tags. In this case, it overrides the album artist. In order
50 # to add artists, the album artist must be listed again. For example, Reba
51 # McEntire's "The Heart Won't Lie" on the album "It's Your Call" features
52 # Vince Gill, and is specified as:
53 # ARTIST=Reba McEntire
54 # ALBUM=It's Your Call
55 # TITLE[5]=The Heart Won't Lie
56 # ARTIST[5]=Reba McEntire
57 # ARTIST[5]=Vince Gill
59 package epg
::flac
::archive
::encode
;
66 require "$FindBin::Bin/tags.p";
67 epg
::flac
::archive
::tags-
>import(
75 my $input_directory = shift;
76 my $fn = "$input_directory/tags";
77 open(my $fh, '<', $fn) || die("open($fn): $!");
78 my ($album, $tracks) = read_tags
($fh);
79 if (!defined($album->{ALBUM
}) || scalar(@{$album->{ALBUM
}}) != 1) {
80 die('exactly one ALBUM tag required')
82 my $album_tag = $album->{ALBUM
}->[0];
84 if (!defined($album->{ARTIST
}) || scalar(@{$album->{ARTIST
}}) != 1) {
85 die('exactly one ARTIST tag required')
87 my $artist = $album->{ARTIST
}->[0];
90 if (defined($album->{DATE
})) {
91 if (scalar(@{$album->{DATE
}}) != 1) {
92 die('one or zero DATE tags required')
94 $date = $album->{DATE
}->[0];
97 if (defined($album->{DISCNUMBER
})) {
98 if (scalar(@{$album->{DISCNUMBER
}}) != 1) {
99 die('one or zero DISCNUMBER tags required')
101 @discnumber = ($album->{DISCNUMBER
}->[0]);
104 my $dir = join('/', '..', mangle_for_file_name
($artist), mangle_for_file_name
($album_tag));
107 say('mkdir -p ', quote
($dir));
109 for my $track (@$tracks) {
111 if (!defined($track->{TITLE
}) || scalar(@{$track->{TITLE
}}) < 1) {
112 die("at least one TITLE required for track $tracknum")
114 $track->{ALBUM
} = $album->{ALBUM
};
115 $track->{TRACKNUMBER
} = [$tracknum];
116 if (!defined($track->{ARTIST
}) && defined($album->{ARTIST
})) {
117 $track->{ARTIST
} = $album->{ARTIST
};
119 if (defined($date)) {
120 $track->{DATE
} = [$date];
123 $track->{DISCNUMBER
} = \
@discnumber;
125 my $title = join(' ', @{$track->{TITLE
}});
126 my $tracknum_s = sprintf('%02d', $tracknum);
130 (map { sprintf('%02d', $_) } @discnumber),
132 mangle_for_file_name
($title) . '.flac',
135 -e
$fn && die("cowardly refusing to clobber $fn");
136 my @pictures = ('--picture', quote
('3|image/jpeg|||cover.front')); # TODO optional
140 '--delete-input-file',
148 ('-T', quote
($name . '=' . $_))
150 } sort(keys(%$track))),
151 "track$tracknum_s.cdda.wav"
154 say('rm tags cover.front');