]>
diplodocus.org Git - flac-archive/blob - fa-rip
8 B<fa-rip> - rip a CD for B<fa-flacd>
12 B<fa-rip> [B<-d> I<device>] [B<-p> I<post-processor> [B<-t> I<track-count>]
23 use Fcntl
qw(O_CREAT O_WRONLY);
25 use Getopt
::Long
qw(:config gnu_getopt no_ignore_case);
26 use POSIX
':sys_wait_h';
29 use MusicBrainz
::Client
::Simple
;
35 $status = system($command);
37 if (WIFEXITED
($status)) {
38 if (($status = WEXITSTATUS
($status)) != 0) {
39 die("$command exited with status $status");
41 } elsif (WIFSIGNALED
($status)) {
42 die("$command killed with signal ", WTERMSIG
($status));
43 } elsif (WIFSTOPPED
($status)) {
44 die("$command stopped with signal ", WSTOPSIG
($status));
46 die("Major horkage on system($command): \$? = $? \$! = $!");
52 my $trackcount = shift;
55 push(@command, 'mkcue');
57 if (defined($trackcount)) {
58 push(@command, "-t $trackcount");
61 if (defined($device)) {
62 push(@command, $device);
65 push(@command, '> cue');
66 run_or_die
(join(' ', @command));
68 if (not defined($trackcount)) {
69 open(F
, 'cue') or die("open(cue): $!");
70 $trackcount = grep(/TRACK.*AUDIO/, <F
>);
79 my $trackcount = shift;
89 if (defined($device)) {
90 $mb = new MusicBrainz
::Client
::Simple
(device
=>$device);
92 $mb = new MusicBrainz
::Client
::Simple
;
95 @results = $mb->lookup_cd;
96 if (not $mb->success) {
100 open(F
, '>candidate-tags-0') or die("open('>candidate-tags-0'): $!");
101 print(F
"$_=\n") for ('ARTIST', 'ALBUM', 'DATE');
102 print(F
"TITLE=\n") for 1 .. $trackcount;
103 close(F
) or die("close('>candidate-tags-0'): $!");
105 for $album (@results) {
107 open(F
, ">candidate-tags-$i") or die("open(>candidate-tags-$i): $!");
109 print(F
'ARTIST=', $album->get_artist->get_name, "\n");
110 print(F
'ALBUM=', $album->get_name, "\n");
112 # MusicBrainz doesn't have dates yet; these are usually wrong anyway.
115 @tracks = $album->get_tracks;
116 for $j (1 .. $trackcount) {
117 if ($track = shift(@tracks)) {
118 $name = $track->get_name;
122 print(F
"TITLE=$name\n");
125 close(F
) or die("close(>candidate-tags-$i): $!");
131 my $trackcount = shift;
133 $device ||= '/dev/cdrom';
135 exec('cdparanoia', '-d', $device, "1-$trackcount", 'wav');
136 # exec prints its own error message so just
140 sub make_post_processor
{
143 defined($command) or return;
145 sysopen(F
, 'post-processor', O_CREAT
| O_WRONLY
, 0555)
146 or die("sysopen(post-processor, O_CREAT | O_WRONLY, 0555): $!");
147 print(F
$command, ' "$@"', "\n");
148 close(F
) or die("close(post-processor, O_CREAT | O_WRONLY, 0555): $!");
158 'device|d=s' => \
$CDDEV,
159 'post-processor|p=s', \
$post_processor,
160 'tracks|t=i' => \
$trackcount,
161 'help|h|?' => \
$help,
163 $help and pod2usage
(-exitstatus
=>0, -verbose
=>1);
165 # File::Temp::tempdir calls die on error.
166 $tempdir = File
::Temp
::tempdir
('flac-archive.XXXXXXXXXX');
167 chdir($tempdir) or die("chdir($tempdir): $!");
169 make_post_processor
($post_processor);
170 $trackcount = mkcue
($CDDEV, $trackcount);
171 tags
($CDDEV, $trackcount);
172 rip
($CDDEV, $trackcount);
180 B<fa-rip> creates a temporary directory for storage of its
181 intermediate files, runs C<mkcue(1)> to create the "cue" file, uses
182 MusicBrainz to generate candidate tags files, and runs
183 C<cdparanoia(1)> to rip the CD to the "wav" file.
185 In order for this CD to be processed by B<fa-flacd>, you must create a
186 "tags" file. This is usually done by renaming one of the
187 candidate-tags files and deleting the others. Don't forget to fill in
188 the DATE tag in the selected candidate before renaming it. If
189 B<fa-rip> could not find any tag information from MusicBrainz, you'll
190 have to fill out the candidate-tags-0 template.
196 =item B<-d> [B<--device>] I<device>
198 Use I<device> as the CD-ROM device, instead of the default
199 "/dev/cdrom" or the environment variable CDDEV.
201 =item B<-p> [B<--post-processor>] I<post-processor>
203 Create a "post-processor" file in the temporary directory containing
204 the line 'I<post-processor> "$@"'. See B<fa-flacd>'s man page for
205 information about this hook.
207 =item B<-t> [B<--tracks>] I<track-count>
209 Archive only the first I<track-count> tracks. This is handy for
210 ignoring data tracks.
220 B<fa-rip> uses this to rip audio and save the cuesheet for a CD. It
221 makes some effort to check some common device names for FreeBSD,
222 Linux, and NetBSD by default.
228 Written by Eric Gillespie <epg@pretzelnet.org>.
230 flac-archive is free software; you may redistribute it and/or modify
231 it under the same terms as Perl itself.
236 # cperl-indent-level: 4
237 # perl-indent-level: 4
238 # indent-tabs-mode: nil
241 # vi: set tabstop=4 expandtab: