[1] | 1 | #!/usr/bin/perl -w |
---|
| 2 | use strict; |
---|
| 3 | |
---|
[22] | 4 | use FindBin qw{$RealBin}; |
---|
| 5 | use lib "$RealBin/lib"; |
---|
[1] | 6 | |
---|
[23] | 7 | use Ripper; |
---|
[1] | 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; |
---|
[38] | 13 | use Audio::FLAC::Header; |
---|
[1] | 14 | |
---|
| 15 | GetOptions( |
---|
[38] | 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, |
---|
[1] | 20 | ); |
---|
| 21 | |
---|
| 22 | # output file |
---|
[23] | 23 | die "Usage: $0 -o <output.flac> [-D <device>]\n" unless $OUTPUT_NAME; |
---|
[1] | 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 | |
---|
[41] | 39 | my $tags = $BARCODE ? { BARCODE => $BARCODE } : {}; |
---|
[23] | 40 | my $ripper = Ripper->new({ device => $CD_DEVICE }); |
---|
[41] | 41 | $ripper->rip_to_flac($archive_flac, $tags); |
---|
[1] | 42 | |
---|
| 43 | print "Rip saved as $archive_flac\n"; |
---|
| 44 | system 'eject', $CD_DEVICE; |
---|