[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 | |
---|
[23] | 39 | my $ripper = Ripper->new({ device => $CD_DEVICE }); |
---|
| 40 | $ripper->rip_to_flac($archive_flac); |
---|
[1] | 41 | |
---|
[38] | 42 | if ($BARCODE) { |
---|
| 43 | print "Writing barcode\n"; |
---|
| 44 | system 'metaflac', '--set-tag', "BARCODE=$BARCODE", $archive_flac; |
---|
| 45 | } |
---|
| 46 | |
---|
[1] | 47 | print "Rip saved as $archive_flac\n"; |
---|
| 48 | system 'eject', $CD_DEVICE; |
---|