source: flacrip/trunk/lib/Ripper.pm @ 23

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

moved the code to do the ripping and converting to FLAC from cd2flac into a separate Ripper module

  • Property svn:executable set to *
File size: 1.3 KB
RevLine 
[23]1package Ripper;
[1]2
[23]3use Moose;
[1]4
[22]5use Tracks;
[1]6
7use File::Temp qw{tempdir};
[23]8use File::Spec::Functions qw{catfile};
[1]9use File::Copy;
10
[23]11has device => ( is => 'rw' );
12has tracks => ( 
13    is => 'rw',
14    handles => [qw{read_disc get_tracks get_cuesheet}],
[1]15);
16
[23]17sub rip_to_flac {
18    my ($self, $archive_flac) = @_;
[22]19
[23]20    $self->tracks(Tracks->new);
21    $self->read_disc($self->device);
[1]22
[23]23    die "No tracks found; is there a CD in the drive?\n" unless @{ $self->get_tracks };
[1]24
[23]25    my $tempdir = tempdir(CLEANUP => 1);
[1]26
[23]27    my $wav_file  = catfile($tempdir, 'cdda.wav');
28    my $flac_file = catfile($tempdir, 'cdda.flac');
29    my $cue_file  = catfile($tempdir, 'cdda.cue');
[1]30
[23]31    # rip
32    my $span = $self->tracks->get_cdparanoia_span;
33    system 'cdparanoia', '-d', $self->device, $span, $wav_file;
34    die "\nRipping canceled\n" if ($? & 127);
[1]35
[23]36    # encode + cuesheet
37    open my $CUE, "> $cue_file";
38    print $CUE $self->get_cuesheet;
39    close $CUE;
40    system 'flac', '-o', $flac_file, '--cuesheet', $cue_file, $wav_file;
41    die "\nFLAC encoding canceled\n" if ($? & 127);
[1]42
[23]43    # MusicBrainz discid metadata
44    my $discid = $self->tracks->get_mbz_discid;
[1]45
[23]46    # copy to permanent location
47    copy($flac_file, $archive_flac);
48    system 'metaflac', '--set-tag', "MUSICBRAINZ_DISCID=$discid", $archive_flac;
49}
[1]50
[23]51# module return
521;
Note: See TracBrowser for help on using the repository browser.