]>
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;
88 open($fh, '>', $fn) or die("open('>$fn'): $!");
89 print($fh 'ARTIST=', (defined($artist) and $artist or ''), "\n");
90 print($fh 'ALBUM=', (defined($album) and $album or ''), "\n");
91 # MusicBrainz doesn't have dates yet; these are usually wrong anyway.
94 for $i (1 .. $trackcount) {
95 $various and print($fh "ARTIST[$i]=\n");
96 if ($track = shift(@_)) {
97 $name = $track->get_name;
101 print($fh "TITLE[$i]=$name\n");
104 close($fh) or die("close(>$fn): $!");
109 my $trackcount = shift;
117 if (defined($device)) {
118 $mb = new MusicBrainz
::Client
::Simple
(device
=>$device);
120 $mb = new MusicBrainz
::Client
::Simple
;
123 @results = $mb->lookup_cd;
124 if (not $mb->success) {
128 tags_file
('candidate-tags-0', $trackcount, 0);
130 for $album (@results) {
133 if ($various = $album->has_various_artists) {
134 if (not $seen_various) {
136 tags_file
('candidate-tags-0v', $trackcount, 1);
140 tags_file
("candidate-tags-$i", $trackcount, $various,
141 $album->get_artist->get_name, $album->get_name,
148 my $trackcount = shift;
150 $device ||= '/dev/cdrom';
152 exec('cdparanoia', '-d', $device, "1-$trackcount", 'wav');
153 # exec prints its own error message so just
157 sub make_post_processor
{
160 defined($command) or return;
162 sysopen(F
, 'post-processor', O_CREAT
| O_WRONLY
, 0555)
163 or die("sysopen(post-processor, O_CREAT | O_WRONLY, 0555): $!");
164 print(F
$command, ' "$@"', "\n");
165 close(F
) or die("close(post-processor, O_CREAT | O_WRONLY, 0555): $!");
175 'device|d=s' => \
$CDDEV,
176 'post-processor|p=s', \
$post_processor,
177 'tracks|t=i' => \
$trackcount,
178 'help|h|?' => \
$help,
180 $help and pod2usage
(-exitstatus
=>0, -verbose
=>1);
182 # File::Temp::tempdir calls die on error.
183 $tempdir = File
::Temp
::tempdir
('flac-archive.XXXXXXXXXX');
184 chdir($tempdir) or die("chdir($tempdir): $!");
186 make_post_processor
($post_processor);
187 $trackcount = mkcue
($CDDEV, $trackcount);
188 tags
($CDDEV, $trackcount);
189 rip
($CDDEV, $trackcount);
197 B<fa-rip> creates a temporary directory for storage of its
198 intermediate files, runs C<mkcue(1)> to create the "cue" file, uses
199 MusicBrainz to generate candidate tags files, and runs
200 C<cdparanoia(1)> to rip the CD to the "wav" file.
202 In order for this CD to be processed by B<fa-flacd>, you must create a
203 "tags" file. This is usually done by renaming one of the
204 candidate-tags files and deleting the others. Don't forget to fill in
205 the DATE tag in the selected candidate before renaming it. If
206 B<fa-rip> could not find any tag information from MusicBrainz, you'll
207 have to fill out the candidate-tags-0 template.
213 =item B<-d> [B<--device>] I<device>
215 Use I<device> as the CD-ROM device, instead of the default
216 "/dev/cdrom" or the environment variable CDDEV.
218 =item B<-p> [B<--post-processor>] I<post-processor>
220 Create a "post-processor" file in the temporary directory containing
221 the line 'I<post-processor> "$@"'. See B<fa-flacd>'s man page for
222 information about this hook.
224 =item B<-t> [B<--tracks>] I<track-count>
226 Archive only the first I<track-count> tracks. This is handy for
227 ignoring data tracks.
237 B<fa-rip> uses this to rip audio and save the cuesheet for a CD. It
238 makes some effort to check some common device names for FreeBSD,
239 Linux, and NetBSD by default.
245 Written by Eric Gillespie <epg@pretzelnet.org>.
247 flac-archive is free software; you may redistribute it and/or modify
248 it under the same terms as Perl itself.
253 # cperl-indent-level: 4
254 # perl-indent-level: 4
255 # indent-tabs-mode: nil
258 # vi: set tabstop=4 expandtab: