]>
diplodocus.org Git - flac-archive/blob - flac2mp3
7 B<flac2mp3> - transcode FLAC file to MP3 files
11 B<flac2mp3> [B<--lame-options> I<lame-options>] [B<-q>] [B<-v>] I<file> [...]
15 B<flac2mp3> transcodes the FLAC files I<file> to MP3 files. I<file>
16 may be the kind of FLAC file B<fa-flacd> generates. That is, it
17 contains a cue sheet, one TITLE tag per track listed therein, and
18 ARTIST, ALBUM, and DATE tags.
25 use POSIX
':sys_wait_h';
27 use Getopt
::Long
qw(:config gnu_getopt no_ignore_case);
38 $verbose and print(STDERR
"$command\n");
39 $status = system($command);
41 if (WIFEXITED
($status)) {
42 if (($status = WEXITSTATUS
($status)) != 0) {
43 die("$command exited with status $status");
45 } elsif (WIFSIGNALED
($status)) {
46 die("$command killed with signal ", WTERMSIG
($status));
47 } elsif (WIFSTOPPED
($status)) {
48 die("$command stopped with signal ", WSTOPSIG
($status));
50 die("Major horkage on system($command): \$? = $? \$! = $!");
55 return sprintf('%02d:%02d.%02d', @_);
62 open(F
, '-|', 'metaflac', '--export-cuesheet-to=-', $fn);
64 /INDEX 01 (\d\d):(\d\d):(\d\d)$/ or next;
65 push(@l, [$1, $2, $3]);
70 my $arg = ["--skip=" . tformat
(@{$l[$i]})];
73 if ($next->[2] == 0) {
74 if ($next->[1] == 0) {
75 push(@$arg, '--until=' . tformat
($next->[0] - 1, 59, 74));
77 push(@$arg, '--until=' . tformat
($next->[0], $next->[1] - 1,
81 push(@$arg, '--until=' . tformat
($next->[0], $next->[1],
88 # If no cue sheet, stick a dummy in here.
96 # Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags
110 open(TAGS
, '-|', 'metaflac', '--export-vc-to=-', $fn)
111 or die("open(metaflac --export-vc-to=- $fn): $!");
115 ($tag, $value) = split(/=/, $_, 2);
119 } elsif (/^ALBUM=/i) {
121 } elsif (/^DATE=/i) {
123 } elsif (/^DISCNUMBER=/i) {
124 $discnum = int($value);
125 } elsif (/^ARTIST\[/i) {
126 push(@$artists, $value);
127 } elsif (/^TRACKNUMBER=/i) {
130 # Intentionally don't match the = on this one, to support the
131 # TITLE[1] .. TITLE[n] tag style.
132 } elsif (/^TITLE/i) {
133 push(@$titles, $value);
136 close(TAGS
) or die("close(metaflac --export-vc-to=- $fn): $?");
138 return ($artist, $album, $date, $discnum, $track);
145 if (defined($$var)) {
146 $$var = "$arg '$$var'";
158 my $track = int(shift);
159 my $skip_arg = shift;
160 my $until_arg = shift;
165 $flac_options = '--silent';
171 push(@tmp, $lame_options);
173 push(@tmp, '--preset standard');
175 $quiet and push(@tmp, '--quiet');
176 $verbose and push(@tmp, '--verbose');
177 $lame_options = join(' ', @tmp);
179 # We'll be putting these in single quotes, so we need to escape
180 # any single quotes in the filename by closing the quote ('),
181 # putting an escaped quote (\'), and then reopening the quote (').
182 for ($fn, $title, $artist, $album, $date) {
183 defined and s/'/'\\''/g;
186 $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
187 $outfile =~ s/\//_
/g
;
189 arg
('--tt', \
$title);
190 arg
('--ta', \
$artist);
191 arg
('--tl', \
$album);
193 arg
('--tn', \
$track);
197 run_or_die
(join(' ', "flac $flac_options -cd $skip_arg $until_arg '$fn'",
198 " | lame $lame_options $title $artist $album $date $track",
205 'lame-options=s', \
$lame_options,
206 'quiet|q' => \
$quiet,
207 'verbose|v' => \
$verbose,
208 'help|h|?' => \
$help,
210 $help and pod2usage
(-exitstatus
=>0, -verbose
=>1);
212 @ARGV or pod2usage
();
214 my @args = get_decode_args
($fn);
215 my (@artists, @titles);
216 my ($artist, $album, $date, $discnum, $track) = get_tags
($fn, \
@artists,
219 # lame doesn't seem to support disc number.
220 defined($discnum) and $album .= " (disc $discnum)";
222 # Stupid hack: only a single-track file should have the
223 # TRACKNUMBER tag, so use it if set for the first pass through
224 # the loop. At the end of the loop, we'll set $track for the
225 # next run, so this continues to work for multi-track files.
228 for my $i (0..$#titles) {
229 flac2mp3
($fn, $titles[$i], ($artists[$i] or $artist), $album, $date,
230 $track, @{$args[$i]});
243 =item B<--lame-options> I<lame-options>
245 Pass I<lame-options> to B<lame>. This ends up being passed to the
246 shell, so feel free to take advantage of that. You'll almost
247 certainly have to put I<lame-options> in single quotes.
249 =item B<-q> [B<--quiet>]
251 Suppress status information. This option is passed along to B<flac>
254 =item B<-v> [B<--verbose>]
256 Print diagnostic information. This option is passed along to B<flac>
263 Written by Eric Gillespie <epg@pretzelnet.org>.
268 # cperl-indent-level: 4
269 # perl-indent-level: 4
270 # indent-tabs-mode: nil
273 # vi: set tabstop=4 expandtab: