]>
diplodocus.org Git - flac-archive/blob - flac2mp3
7 B<flac2mp3> - transcode FLAC file to MP3 files
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';
32 $status = system($command);
34 if (WIFEXITED
($status)) {
35 if (($status = WEXITSTATUS
($status)) != 0) {
36 die("$command exited with status $status");
38 } elsif (WIFSIGNALED
($status)) {
39 die("$command killed with signal ", WTERMSIG
($status));
40 } elsif (WIFSTOPPED
($status)) {
41 die("$command stopped with signal ", WSTOPSIG
($status));
43 die("Major horkage on system($command): \$? = $? \$! = $!");
48 return sprintf('%02d:%02d.%02d', @_);
55 open(F
, '-|', 'metaflac', '--export-cuesheet-to=-', $fn);
57 /INDEX 01 (\d\d):(\d\d):(\d\d)$/ or next;
58 push(@l, [$1, $2, $3]);
63 my $arg = ["--skip=" . tformat
(@{$l[$i]})];
66 if ($next->[2] == 0) {
67 if ($next->[1] == 0) {
68 push(@$arg, '--until=' . tformat
($next->[0] - 1, 59, 74));
70 push(@$arg, '--until=' . tformat
($next->[0], $next->[1] - 1,
74 push(@$arg, '--until=' . tformat
($next->[0], $next->[1],
84 # Return the ARTIST, ALBUM, and DATE tags followed by the TITLE tags
95 open(TAGS
, '-|', 'metaflac', '--export-vc-to=-', $fn)
96 or die("open(metaflac --export-vc-to=- $fn): $!");
100 ($tag, $value) = split(/=/, $_, 2);
104 } elsif (/^ALBUM=/) {
109 push(@titles, $value);
112 close(TAGS
) or die("close(metaflac --export-vc-to=- $fn): $?");
114 return ($artist, $album, $date, @titles);
124 my $skip_arg = shift;
125 my $until_arg = shift;
128 # We'll be putting these in single quotes, so we need to escape
129 # any single quotes in the filename by closing the quote ('),
130 # putting an escaped quote (\'), and then reopening the quote (').
131 for ($fn, $title, $artist, $album, $date) {
135 $outfile = sprintf("$artist ($album) \%02s $title.mp3", $track);
136 $outfile =~ s/\//_
/g
;
139 run_or_die
(join(' ', "flac -cd $skip_arg $until_arg '$fn'",
140 " | lame --preset standard --tt '$title' --ta '$artist'",
141 " --tl '$album' --ty '$date' --tn $track - '$outfile'"));
145 my $fn = shift or pod2usage
();
146 my @args = get_decode_args
($fn);
147 my ($artist, $album, $date, @titles) = get_tags
($fn);
149 for my $i (0..$#titles) {
150 flac2mp3
($fn, $titles[$i], $artist, $album, $date, $i + 1,
160 Written by Eric Gillespie <epg@pretzelnet.org>.
165 # cperl-indent-level: 4
166 # perl-indent-level: 4
167 # indent-tabs-mode: nil
170 # vi: set tabstop=4 expandtab: