]>
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 file I<file> to MP3 files. I<file> is
16 the kind of FLAC file B<fa-flacd> generates. That is, it contains a
17 cue sheet, one TITLE tag per track listed therein, and ARTIST, ALBUM,
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],
91 # Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags
102 open(TAGS
, '-|', 'metaflac', '--export-vc-to=-', $fn)
103 or die("open(metaflac --export-vc-to=- $fn): $!");
107 ($tag, $value) = split(/=/, $_, 2);
111 } elsif (/^ALBUM=/) {
116 # Intentionally don't match the = on this one, to support the
117 # TITLE[1] .. TITLE[n] tag style.
119 push(@titles, $value);
122 close(TAGS
) or die("close(metaflac --export-vc-to=- $fn): $?");
124 return ($artist, $album, $date, @titles);
134 my $skip_arg = shift;
135 my $until_arg = shift;
140 $flac_options = '--silent';
146 push(@tmp, $lame_options);
148 push(@tmp, '--preset standard');
150 $quiet and push(@tmp, '--quiet');
151 $verbose and push(@tmp, '--verbose');
152 $lame_options = join(' ', @tmp);
154 # We'll be putting these in single quotes, so we need to escape
155 # any single quotes in the filename by closing the quote ('),
156 # putting an escaped quote (\'), and then reopening the quote (').
157 for ($fn, $title, $artist, $album, $date) {
161 $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
162 $outfile =~ s/\//_
/g
;
165 run_or_die
(join(' ', "flac $flac_options -cd $skip_arg $until_arg '$fn'",
166 " | lame $lame_options --tt '$title' --ta '$artist'",
167 " --tl '$album' --ty '$date' --tn $track - '$outfile'"));
173 'lame-options=s', \
$lame_options,
174 'quiet|q' => \
$quiet,
175 'verbose|v' => \
$verbose,
176 'help|h|?' => \
$help,
178 $help and pod2usage
(-exitstatus
=>0, -verbose
=>1);
180 my $fn = shift or pod2usage
();
181 my @args = get_decode_args
($fn);
182 my ($artist, $album, $date, @titles) = get_tags
($fn);
184 for my $i (0..$#titles) {
185 flac2mp3
($fn, $titles[$i], $artist, $album, $date, $i + 1,
197 =item B<--lame-options> I<lame-options>
199 Pass I<lame-options> to B<lame>. This ends up being passed to the
200 shell, so feel free to take advantage of that. You'll almost
201 certainly have to put I<lame-options> in single quotes.
203 =item B<-q> [B<--quiet>]
205 Suppress status information. This option is passed along to B<flac>
208 =item B<-v> [B<--verbose>]
210 Print diagnostic information. This option is passed along to B<flac>
217 Written by Eric Gillespie <epg@pretzelnet.org>.
222 # cperl-indent-level: 4
223 # perl-indent-level: 4
224 # indent-tabs-mode: nil
227 # vi: set tabstop=4 expandtab: