ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-CD/lib/Convert/CD/Cue.pm
Revision: 1.7
Committed: Tue Jun 10 15:54:26 2003 UTC (23 years, 3 months ago) by root
Branch: MAIN
Changes since 1.6: +17 -4 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     Convert::CD::Cue - import/export .bin/.cue files.
4    
5     =head1 SYNOPSIS
6    
7     use Convert::CD::Cue;
8    
9     # to be done
10    
11     =head1 DESCRIPTION
12    
13     Parse/Write .cue files.
14    
15     =head2 Convert:CD::Cue METHODS
16    
17     This class represents a .bin/.cue file combination.
18    
19     =over 4
20    
21     =cut
22    
23     package Convert::CD::Cue;
24    
25     $VERSION = 0.01;
26    
27 root 1.3 use Carp;
28    
29 root 1.1 use base Convert::CD::TOCFile;
30    
31     =item new param => value...
32    
33     Create a new Convert::CD::Cue object.
34    
35     Parameters:
36    
37     path the base image filename
38     tocpath the (optional) path of the tocfile
39    
40     =cut
41    
42     sub new {
43     my $class = shift;
44     my $self = bless { @_, }, $class;
45 root 1.3 exists $self->{tocpath} or $self->{tocpath} = $self->find_tocfile ("cue", "CUE", "Cue");
46 root 1.1 $self;
47     }
48    
49 root 1.2 sub _read {
50     my ($self, $cd) = @_;
51    
52 root 1.3 defined $self->{tocpath}
53     or croak "no tocpath specified and/or no .cue found";
54    
55 root 1.2 open my $cue, "<", $self->{tocpath}
56 root 1.3 or croak "$self->{tocpath}: $!";
57    
58 root 1.5 my @tracks; # perliminary track data
59     my $file;
60     my $track;
61    
62 root 1.3 # assumption #1: these thingies are line-based
63     while (<$cue>) {
64     s/[\015\012]+$//;
65 root 1.5 # assumption #2, leading whitespace don't matter much
66 root 1.3 # assumption #3, case? what case?
67 root 1.5 if (/\S*FILE \"?(.*?)\"? (\S+)$/i) {
68     my ($path, $type) = ($1, $2);
69     if (-e $path) {
70     $file = $path;
71     } else {
72     my $name = $path; $name =~ s/^.*[\/\\]//;
73     if (-e $name) {
74     $file = $name;
75     } elsif (-e lc $name) {
76     $file = lc $name;
77     } else {
78     $file = $self->{path};
79     }
80     warn "\"$path\" not found, using \"$file\" instead\n";
81     }
82    
83     } elsif (/\S*TRACK (\d+) (\S+)/i) {
84     my ($idx, $mode) = ($1, $2);
85     my $secsize = 2352;
86    
87     $secsize = $1 if $mode =~ s/\/(\d+)$//; # MODE2/1234 => MODE2
88 root 1.7
89     $mode = MODE_AUDIO if $mode eq "AUDIO";
90     $mode = MODE_MODE1 if $mode eq "MODE1";
91     $mode = MODE_MODE2 if $mode eq "MODE2";
92     $mode = MODE_CDI if $mode eq "CDI";
93     $mode = MODE_CDG if $mode eq "CDG";
94    
95     if ($mode == 0) {
96     warn "unrecognized mode '$mode', using MODE2 instead\n";
97     $mode = MODE_MODE2;
98     }
99    
100     $secsize = 2448 if $mode == MODE_CDG;
101 root 1.5
102     $track = $tracks[$idx - 1] = {};
103    
104 root 1.7 $track->{path} = $file;
105     $track->{mode} = $mode;
106     $track->{secsize} = $secsize;
107 root 1.5
108     } elsif (/\S*INDEX (\d+) ([0-9:]+)/i) {
109     my ($idx, $time) = ($1, $self->parse_msf ($2));
110    
111     $track->{index}[$idx] = $time;
112     $track->{offset} = $time * $track->{secsize} if $idx == 1;
113    
114     } elsif (/\S*PREGAP ([0-9:]+)/i) {
115 root 1.6 $track->{pregap} = $self->parse_msf ($1);
116 root 1.5
117     } elsif (/\S*POSTGAP ([0-9:]+)/i) {
118 root 1.6 $track->{postgap} = $self->parse_msf ($1);
119 root 1.5
120 root 1.7 # need to parse FLAGS
121 root 1.3 } else {
122     warn "unknown .cue directive skipped: $_";
123 root 1.5 }
124     }
125    
126     # now go through the tracks array
127     my $prev = undef;
128     for (@tracks) {
129     next unless $_;
130     if ($prev && $prev->{offset} <= $_->{offset}) {
131 root 1.6 $prev->{rawsize} = $_->{offset} - $prev->{offset};
132 root 1.5 }
133     $prev = $_;
134     }
135    
136     for (@tracks) {
137     if (defined $_) {
138     $cd->append_track (%$_);
139     } else {
140     # synthesize empty track
141     $cd->append_track (size => 0, mode => "MODE1", secsize => 2048);
142 root 1.3 }
143     }
144 root 1.2 }
145 root 1.1
146     #sub _write {
147     # my ($self, $cd) = @_;
148     #}
149    
150     1;
151    
152     =back
153    
154     =head1 AUTHOR
155    
156     Marc Lehmann <pcg@goof.com>
157    
158     =cut
159