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

Last change on this file since 25 was 24, checked in by peter, 10 years ago
  • converted Tracks from Class::Std to Moose
  • added a has_tracks() method to Tracks
  • Property svn:executable set to *
File size: 1.3 KB
Line 
1package Ripper;
2
3use Moose;
4
5use Tracks;
6
7use File::Temp qw{tempdir};
8use File::Spec::Functions qw{catfile};
9use File::Copy;
10
11has device => ( is => 'rw' );
12has tracks => ( 
13    is => 'rw',
14    handles => [qw{read_disc has_tracks get_cuesheet}],
15);
16
17sub rip_to_flac {
18    my ($self, $archive_flac) = @_;
19
20    $self->tracks(Tracks->new);
21    $self->read_disc($self->device);
22
23    die "No tracks found; is there a CD in the drive?\n" unless $self->has_tracks;
24
25    my $tempdir = tempdir(CLEANUP => 1);
26
27    my $wav_file  = catfile($tempdir, 'cdda.wav');
28    my $flac_file = catfile($tempdir, 'cdda.flac');
29    my $cue_file  = catfile($tempdir, 'cdda.cue');
30
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);
35
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);
42
43    # MusicBrainz discid metadata
44    my $discid = $self->tracks->get_mbz_discid;
45
46    # copy to permanent location
47    copy($flac_file, $archive_flac);
48    system 'metaflac', '--set-tag', "MUSICBRAINZ_DISCID=$discid", $archive_flac;
49}
50
51# module return
521;
Note: See TracBrowser for help on using the repository browser.