source: flacrip/trunk/cd2flac @ 41

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

Use Audio::FLAC::Header to write the tags to the FLAC file instead of making
external calls to metaflac. In addition, rip_to_flac now returns a
DiscFlacFile object.

  • Property svn:executable set to *
File size: 1.2 KB
RevLine 
[1]1#!/usr/bin/perl -w
2use strict;
3
[22]4use FindBin qw{$RealBin};
5use lib "$RealBin/lib";
[1]6
[23]7use Ripper;
[1]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;
[38]13use Audio::FLAC::Header;
[1]14
15GetOptions(
[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]23die "Usage: $0 -o <output.flac> [-D <device>]\n" unless $OUTPUT_NAME;
[1]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
[41]39my $tags = $BARCODE ? { BARCODE => $BARCODE } : {};
[23]40my $ripper = Ripper->new({ device => $CD_DEVICE });
[41]41$ripper->rip_to_flac($archive_flac, $tags);
[1]42
43print "Rip saved as $archive_flac\n";
44system 'eject', $CD_DEVICE;
Note: See TracBrowser for help on using the repository browser.