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

Last change on this file since 28 was 28, checked in by peter, 9 years ago

made discid an attribute of the Tracks class, instead of a method

  • Property svn:executable set to *
File size: 1.4 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->_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->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
51sub _get_cdparanoia_span {
52    my ($self) = @_;
53    # use a msf start unless track 1 begins at sector
54    return $self->tracks->tracks->[1]{sector} == 0 ? '1-' : '00:00.00-';
55}
56
57# module return
581;
Note: See TracBrowser for help on using the repository browser.