Changeset 22 in flacrip for trunk/lib


Ignore:
Timestamp:
10/08/14 20:38:14 (10 years ago)
Author:
peter
Message:
  • split the Tracks module out into its own *.pm file
  • cd2flac dies unless there is an output file argument given
File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/Tracks.pm

    r21 r22  
    1 #!/usr/bin/perl -w 
     1package Tracks; 
     2 
    23use strict; 
    3  
    4 package Tracks; 
     4use warnings; 
    55 
    66use Class::Std; 
     
    115115} 
    116116 
    117 package main; 
    118 use File::Temp qw{tempdir}; 
    119 use File::Spec::Functions qw{catfile splitpath}; 
    120 use File::Copy; 
    121 use File::Path qw{mkpath}; 
    122 use Getopt::Long qw{:config no_ignore_case no_auto_abbrev}; 
    123 use Cwd; 
    124  
    125 GetOptions( 
    126     'device|D=s' => \my $CD_DEVICE, 
    127     'output|o=s' => \my $OUTPUT_NAME, 
    128     'force|f'    => \my $FORCE, 
    129 ); 
    130  
    131 # output file 
    132 my (undef, $out_dir, $out_file) = splitpath($OUTPUT_NAME); 
    133 # automatically add ".flac" 
    134 $out_file .= '.flac' unless $out_file =~ /\.flac$/; 
    135 # default to current directory 
    136 $out_dir ||= getcwd; 
    137 mkpath($out_dir) unless -e $out_dir; 
    138 my $archive_flac = catfile($out_dir, $out_file); 
    139  
    140 # check for file exist; default to not overwrite 
    141 die "$archive_flac exists\nwill not overwrite (use --force to override this)\n"  
    142     if -e $archive_flac && !$FORCE; 
    143  
    144 # get the CD info 
    145 $CD_DEVICE ||= '/dev/cdrom'; 
    146 my $tracks = Tracks->new; 
    147 $tracks->read_disc($CD_DEVICE); 
    148  
    149 die "No tracks found; is there a CD in the drive?\n" unless @{ $tracks->get_tracks }; 
    150  
    151 my $tempdir = tempdir(CLEANUP => 1); 
    152  
    153 my $wav_file  = catfile($tempdir, 'cdda.wav'); 
    154 my $flac_file = catfile($tempdir, 'cdda.flac'); 
    155 my $cue_file  = catfile($tempdir, 'cdda.cue'); 
    156  
    157 # rip 
    158 my $span = $tracks->get_cdparanoia_span; 
    159 system 'cdparanoia', '-d', $CD_DEVICE, $span, $wav_file; 
    160 die "\nRipping canceled\n" if ($? & 127); 
    161  
    162  
    163 # encode + cuesheet 
    164 open my $CUE, "> $cue_file"; 
    165 print $CUE $tracks->get_cuesheet; 
    166 close $CUE; 
    167 system 'flac', '-o', $flac_file, '--cuesheet', $cue_file, $wav_file; 
    168 die "\nFLAC encoding canceled\n" if ($? & 127); 
    169  
    170 # MusicBrainz discid metadata 
    171 my $discid = $tracks->get_mbz_discid; 
    172  
    173 # copy to permanent location 
    174 copy($flac_file, $archive_flac); 
    175 system 'metaflac', '--set-tag', "MUSICBRAINZ_DISCID=$discid", $archive_flac; 
    176 print "Rip saved as $archive_flac\n"; 
    177 system 'eject', $CD_DEVICE; 
     117# module return 
     1181; 
Note: See TracChangeset for help on using the changeset viewer.