]>
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<-t> I<track-count>]
24 use Getopt
::Long
qw(:config gnu_getopt no_ignore_case);
25 use POSIX
':sys_wait_h';
28 use MusicBrainz
::Client
::Simple
;
34 $status = system($command);
36 if (WIFEXITED
($status)) {
37 if (($status = WEXITSTATUS
($status)) != 0) {
38 die("$command exited with status $status");
40 } elsif (WIFSIGNALED
($status)) {
41 die("$command killed with signal ", WTERMSIG
($status));
42 } elsif (WIFSTOPPED
($status)) {
43 die("$command stopped with signal ", WSTOPSIG
($status));
45 die("Major horkage on system($command): \$? = $? \$! = $!");
51 my $trackcount = shift;
54 push(@command, 'mkcue');
56 if (defined($trackcount)) {
57 push(@command, "-t $trackcount");
60 if (defined($device)) {
61 push(@command, $device);
64 push(@command, '> cue');
65 run_or_die
(join(' ', @command));
67 if (not defined($trackcount)) {
68 open(F
, 'cue') or die("open(cue): $!");
69 $trackcount = grep(/TRACK.*AUDIO/, <F
>);
78 my $trackcount = shift;
88 if (defined($device)) {
89 $mb = new MusicBrainz
::Client
::Simple
(device
=>$device);
91 $mb = new MusicBrainz
::Client
::Simple
;
94 @results = $mb->lookup_cd;
95 if (not $mb->success) {
99 open(F
, '>candidate-tags-0') or die("open('>candidate-tags-0'): $!");
100 print(F
"$_=\n") for ('ARTIST', 'ALBUM', 'DATE');
101 print(F
"TITLE=\n") for 1 .. $trackcount;
102 close(F
) or die("close('>candidate-tags-0'): $!");
104 for $album (@results) {
106 open(F
, ">candidate-tags-$i") or die("open(>candidate-tags-$i): $!");
108 print(F
'ARTIST=', $album->get_artist->get_name, "\n");
109 print(F
'ALBUM=', $album->get_name, "\n");
111 # MusicBrainz doesn't have dates yet; these are usually wrong anyway.
114 @tracks = $album->get_tracks;
115 for $j (1 .. $trackcount) {
116 if ($track = shift(@tracks)) {
117 $name = $track->get_name;
121 print(F
"TITLE=$name\n");
124 close(F
) or die("close(>candidate-tags-$i): $!");
130 my $trackcount = shift;
132 $device ||= '/dev/cdrom';
134 exec('cdparanoia', '-d', $device, "1-$trackcount", 'wav');
135 # exec prints its own error message so just
145 'device|d=s' => \
$CDDEV,
146 'tracks|t=i' => \
$trackcount,
147 'help|h|?' => \
$help,
149 $help and pod2usage
(-exitstatus
=>0, -verbose
=>1);
151 # File::Temp::tempdir calls die on error.
152 $tempdir = File
::Temp
::tempdir
('flac-archive.XXXXXXXXXX');
153 chdir($tempdir) or die("chdir($tempdir): $!");
155 $trackcount = mkcue
($CDDEV, $trackcount);
156 tags
($CDDEV, $trackcount);
157 rip
($CDDEV, $trackcount);
165 B<fa-rip> creates a temporary directory for storage of its
166 intermediate files, runs C<mkcue(1)> to create the "cue" file, uses
167 MusicBrainz to generate candidate tags files, and runs
168 C<cdparanoia(1)> to rip the CD to the "wav" file.
170 In order for this CD to be processed by B<fa-flacd>, you must create a
171 "tags" file. This is usually done by renaming one of the
172 candidate-tags files and deleting the others. Don't forget to fill in
173 the DATE tag in the selected candidate before renaming it. If
174 B<fa-rip> could not find any tag information from MusicBrainz, you'll
175 have to fill out the candidate-tags-0 template.
181 =item B<-d> [B<--device>] I<device>
183 Use I<device> as the CD-ROM device, instead of the default
184 "/dev/cdrom" or the environment variable CDDEV.
186 =item B<-t> [B<--tracks>] I<track-count>
188 Archive only the first I<track-count> tracks. This is handy for
189 ignoring data tracks.
199 B<fa-rip> uses this to rip audio and save the cuesheet for a CD. It
200 makes some effort to check some common device names for FreeBSD,
201 Linux, and NetBSD by default.
207 Written by Eric Gillespie <epg@pretzelnet.org>.
209 flac-archive is free software; you may redistribute it and/or modify
210 it under the same terms as Perl itself.
215 # cperl-indent-level: 4
216 # perl-indent-level: 4
217 # indent-tabs-mode: nil
220 # vi: set tabstop=4 expandtab: