]> diplodocus.org Git - flac-archive/blob - flac2mp3
Restore PART/VERSION and add filename tests.
[flac-archive] / flac2mp3
1 #!/usr/local/bin/perl
2
3 =head1 NAME
4
5 B<flac2mp3> - transcode FLAC file to MP3 files
6
7 =head1 SYNOPSIS
8
9 B<flac2mp3> [B<--lame-options> I<lame-options>] [B<-q>] [B<-v>] I<file> [...]
10
11 =head1 DESCRIPTION
12
13 B<flac2mp3> transcodes the FLAC files I<file> to MP3 files. I<file>
14 may be the kind of FLAC file B<fa-flacd> generates. That is, it
15 contains a cue sheet, one TITLE tag per track listed therein, and
16 ARTIST, ALBUM, and DATE tags.
17
18 Note that lame is retarded, and parses B<LANG> directly itself! So, in order
19 for it to transcode textual tags, you must specify the encoding in LANG, e.g.
20 LANG=en_US.utf-8
21
22 =head1 OPTIONS
23
24 =over 4
25
26 =item B<--lame-options> I<lame-options>
27
28 Pass I<lame-options> to B<lame>. This ends up being passed to the
29 shell, so feel free to take advantage of that. You'll almost
30 certainly have to put I<lame-options> in single quotes.
31
32 =item B<-q> [B<--quiet>]
33
34 Suppress status information. This option is passed along to B<flac>
35 and B<lame>.
36
37 =item B<-v> [B<--verbose>]
38
39 Print diagnostic information. This option is passed along to B<flac>
40 and B<lame>.
41
42 =back
43
44 =head1 AUTHORS
45
46 Written by Eric Gillespie <epg@pretzelnet.org>.
47
48 =cut
49
50 package epg::flac::archive::mp3;
51
52 use v5.12;
53 use warnings;
54
55 use FindBin;
56
57 use lib $FindBin::Bin;
58
59 require 'tags.pl';
60 epg::flac::archive::tags->import(
61 qw[
62 track_tags
63 read_tags_metaflac
64 mangle_for_file_name
65 quote
66 two_digits
67 ]
68 );
69
70 sub flac2mp3 {
71 my $mp3 = shift;
72 my $flac = shift;
73 my $tags = shift;
74
75 # This is an old TODO; what's wrong with --ty ?
76 # TODO: Look at TDOR, TDRL, TDRC for date.
77 say(
78 join(
79 ' ',
80 'flac',
81 '-cd',
82 quote($flac),
83 '|',
84 'lame',
85 '--id3v2-only',
86 '--id3v2-latin1',
87 '--pad-id3v2-size', 0,
88 '--preset standard',
89 '--ta',
90 quote($tags->{artist}),
91 '--tl',
92 quote($tags->{album}),
93 '--tn',
94 quote($tags->{tracknumber}),
95 '--tt',
96 quote($tags->{title}),
97 '--ty',
98 quote($tags->{date}),
99 '$pic_options',
100
101 #(map { ('--tv', quote("TPE2=$_")) } @{$albumartist}),
102 (map { ('--tv', quote("TPOS=$_")) } @{$tags->{discnumber}}),
103 '-',
104 quote($mp3),
105 )
106 );
107 }
108
109 sub filename {
110 my $tags = shift;
111 mangle_for_file_name(
112 join(' ',
113 @{$tags->{ARTIST}},
114 @{$tags->{ALBUM}},
115 (map { two_digits($_) } @{$tags->{DISCNUMBER} // []}),
116 (map { two_digits($_) } @{$tags->{TRACKNUMBER} // []}),
117 @{$tags->{TITLE}},
118 @{$tags->{VERSION} // []},
119 @{$tags->{PARTNUMBER} // []},
120 )
121 ) . '.mp3';
122 }
123
124 sub main {
125 for my $flac (@_) {
126 say('metaflac --export-picture-to=flac2mp3.cover.$$ ',
127 quote($flac), ' && pic_options="--ti flac2mp3.cover.$$"');
128
129 # TODO multi-track
130 my ($tags) = read_tags_metaflac($flac);
131 flac2mp3(filename($tags), $flac, {track_tags($tags)});
132 say('unset pic_options');
133 }
134 say('rm -f flac2mp3.cover.$$');
135
136 return 0;
137 }
138
139 if (!caller) {
140 exit(main(@ARGV));
141 }
142
143 1;