1 | #!/usr/bin/perl -w |
---|
2 | use strict; |
---|
3 | |
---|
4 | use FindBin qw{$RealBin}; |
---|
5 | use lib "$RealBin/lib"; |
---|
6 | |
---|
7 | use Ripper; |
---|
8 | |
---|
9 | use File::Spec::Functions qw{catfile splitpath}; |
---|
10 | use File::Path qw{mkpath}; |
---|
11 | use Getopt::Long qw{:config no_ignore_case no_auto_abbrev}; |
---|
12 | use Cwd; |
---|
13 | use Audio::FLAC::Header; |
---|
14 | |
---|
15 | GetOptions( |
---|
16 | 'device|D=s' => \my $CD_DEVICE, |
---|
17 | 'output|o=s' => \my $OUTPUT_NAME, |
---|
18 | 'force|f' => \my $FORCE, |
---|
19 | 'barcode|b=s' => \my $BARCODE, |
---|
20 | ); |
---|
21 | |
---|
22 | # output file |
---|
23 | die "Usage: $0 -o <output.flac> [-D <device>]\n" unless $OUTPUT_NAME; |
---|
24 | my (undef, $out_dir, $out_file) = splitpath($OUTPUT_NAME); |
---|
25 | # automatically add ".flac" |
---|
26 | $out_file .= '.flac' unless $out_file =~ /\.flac$/; |
---|
27 | # default to current directory |
---|
28 | $out_dir ||= getcwd; |
---|
29 | mkpath($out_dir) unless -e $out_dir; |
---|
30 | my $archive_flac = catfile($out_dir, $out_file); |
---|
31 | |
---|
32 | # check for file exist; default to not overwrite |
---|
33 | die "$archive_flac exists\nwill not overwrite (use --force to override this)\n" |
---|
34 | if -e $archive_flac && !$FORCE; |
---|
35 | |
---|
36 | # get the CD info |
---|
37 | $CD_DEVICE ||= '/dev/cdrom'; |
---|
38 | |
---|
39 | my $tags = $BARCODE ? { BARCODE => $BARCODE } : {}; |
---|
40 | my $ripper = Ripper->new({ device => $CD_DEVICE }); |
---|
41 | $ripper->rip_to_flac($archive_flac, $tags); |
---|
42 | |
---|
43 | print "Rip saved as $archive_flac\n"; |
---|
44 | system 'eject', $CD_DEVICE; |
---|