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

Last change on this file since 27 was 26, checked in by peter, 10 years ago
  • added parse_cuesheet() function to Tracks
  • Tracks can now read tracks in from the CUESHEET block of a FLAC file (read_flac) or from a cue file directly (read_cue)
  • Tracks can caluclate the MusicBrainz TOC lookup string (get_musicbrainz_tocdata)
  • renamed the get_mbz_discid method to get_musicbrainz_discid
  • moved the get_cdparanoia_span method into the Ripper class and made it private
  • 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 => ( 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->get_musicbrainz_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.