source: flacrip/trunk/cd2flac @ 39

Last change on this file since 39 was 38, checked in by peter, 10 years ago

issue #4: set BARCODE tag after successful rip_to_flac() operation

  • Property svn:executable set to *
File size: 1.3 KB
Line 
1#!/usr/bin/perl -w
2use strict;
3
4use FindBin qw{$RealBin};
5use lib "$RealBin/lib";
6
7use Ripper;
8
9use File::Spec::Functions qw{catfile splitpath};
10use File::Path qw{mkpath};
11use Getopt::Long qw{:config no_ignore_case no_auto_abbrev};
12use Cwd;
13use Audio::FLAC::Header;
14
15GetOptions(
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
23die "Usage: $0 -o <output.flac> [-D <device>]\n" unless $OUTPUT_NAME;
24my (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;
29mkpath($out_dir) unless -e $out_dir;
30my $archive_flac = catfile($out_dir, $out_file);
31
32# check for file exist; default to not overwrite
33die "$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
39my $ripper = Ripper->new({ device => $CD_DEVICE });
40$ripper->rip_to_flac($archive_flac);
41
42if ($BARCODE) {
43    print "Writing barcode\n";
44    system 'metaflac', '--set-tag', "BARCODE=$BARCODE", $archive_flac;
45}
46
47print "Rip saved as $archive_flac\n";
48system 'eject', $CD_DEVICE;
Note: See TracBrowser for help on using the repository browser.