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

Last change on this file since 40 was 29, checked in by peter, 10 years ago
  • added types to the attributes in the Tracks and Ripper classes
  • removed get_cuesheet from the list of mathods handled by the Tracks class for the Ripper class
  • Property svn:executable set to *
File size: 1.5 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 => (
12    is  => 'rw',
13    isa => 'Str',
14);
15has tracks => ( 
16    is      => 'rw',
17    isa     => 'Tracks',
18    handles => [qw{read_disc has_tracks}],
19);
20
21sub rip_to_flac {
22    my ($self, $archive_flac) = @_;
23
24    $self->tracks(Tracks->new);
25    $self->read_disc($self->device);
26
27    die "No tracks found; is there a CD in the drive?\n" unless $self->has_tracks;
28
29    my $tempdir = tempdir(CLEANUP => 1);
30
31    my $wav_file  = catfile($tempdir, 'cdda.wav');
32    my $flac_file = catfile($tempdir, 'cdda.flac');
33    my $cue_file  = catfile($tempdir, 'cdda.cue');
34
35    # rip
36    my $span = $self->_get_cdparanoia_span;
37    system 'cdparanoia', '-d', $self->device, $span, $wav_file;
38    die "\nRipping canceled\n" if ($? & 127);
39
40    # encode + cuesheet
41    open my $CUE, "> $cue_file";
42    print $CUE $self->tracks->get_cuesheet;
43    close $CUE;
44    system 'flac', '-o', $flac_file, '--cuesheet', $cue_file, $wav_file;
45    die "\nFLAC encoding canceled\n" if ($? & 127);
46
47    # MusicBrainz discid metadata
48    my $discid = $self->tracks->discid;
49
50    # copy to permanent location
51    copy($flac_file, $archive_flac);
52    system 'metaflac', '--set-tag', "MUSICBRAINZ_DISCID=$discid", $archive_flac;
53}
54
55sub _get_cdparanoia_span {
56    my ($self) = @_;
57    # use a msf start unless track 1 begins at sector
58    return $self->tracks->tracks->[1]{sector} == 0 ? '1-' : '00:00.00-';
59}
60
61# module return
621;
Note: See TracBrowser for help on using the repository browser.