]> diplodocus.org Git - flac-archive/blob - flac2mp3
rename to test more filenames
[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 File::Temp;
56 use FindBin;
57
58 require "$FindBin::Bin/tags.pl";
59 epg::flac::archive::tags->import(
60 qw[
61 track_tags
62 read_tags_metaflac
63 mangle_for_file_name
64 quote
65 two_digits
66 ]);
67
68 sub flac2mp3 {
69 my $mp3 = shift;
70 my $flac = shift;
71 my $tags = shift;
72 # This is an old TODO; what's wrong with --ty ?
73 # TODO: Look at TDOR, TDRL, TDRC for date.
74 say(join(' ',
75 'flac',
76 '-cd',
77 quote($flac),
78 '|',
79 'lame',
80 '--id3v2-only',
81 '--id3v2-latin1',
82 '--pad-id3v2-size', 0,
83 '--preset standard',
84 '--ta',
85 quote($tags->{artist}),
86 '--tl',
87 quote($tags->{album}),
88 '--tn',
89 quote($tags->{tracknumber}),
90 '--tt',
91 quote($tags->{title}),
92 '--ty',
93 quote($tags->{date}),
94 '$pic_options',
95 #(map { ('--tv', quote("TPE2=$_")) } @{$albumartist}),
96 (map { ('--tv', quote("TPOS=$_")) } @{$tags->{discnumber}}),
97 '-',
98 quote($mp3),
99 ))
100 }
101
102 sub main {
103 for my $flac (@_) {
104 say('metaflac --export-picture-to=flac2mp3.cover.$$ ', quote($flac), ' && pic_options="--ti flac2mp3.cover.$$"');
105 my %tags = track_tags(read_tags_metaflac($flac));
106 flac2mp3(
107 mangle_for_file_name(
108 join(' ',
109 $tags{artist},
110 $tags{album},
111 (map { two_digits($_) } @{$tags{discnumber}}),
112 two_digits($tags{tracknumber}),
113 $tags{title},
114 ))
115 . '.mp3',
116 $flac,
117 \%tags,
118 );
119 say('unset pic_options');
120 }
121 say('rm -f flac2mp3.cover.$$');
122
123 return 0;
124 }
125
126 if (!caller) {
127 exit(main(@ARGV))
128 }
129
130 1;