ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Convert-CD/lib/Convert/CD/Cue.pm
Revision: 1.5
Committed: Tue Jun 10 12:47:49 2003 UTC (23 years, 3 months ago) by root
Branch: MAIN
Changes since 1.4: +65 -11 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 use Carp;
28
29 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 exists $self->{tocpath} or $self->{tocpath} = $self->find_tocfile ("cue", "CUE", "Cue");
46 $self;
47 }
48
49 sub _read {
50 my ($self, $cd) = @_;
51
52 defined $self->{tocpath}
53 or croak "no tocpath specified and/or no .cue found";
54
55 open my $cue, "<", $self->{tocpath}
56 or croak "$self->{tocpath}: $!";
57
58 my @tracks; # perliminary track data
59 my $file;
60 my $track;
61
62 # assumption #1: these thingies are line-based
63 while (<$cue>) {
64 s/[\015\012]+$//;
65 # assumption #2, leading whitespace don't matter much
66 # assumption #3, case? what case?
67 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 $secsize = 2448 if $mode eq "CDG";
89
90 $track = $tracks[$idx - 1] = {};
91
92 $track->{path} = $file;
93 $track->{mode} = $mode;
94 $track->{secsize} = $secsize;
95
96 } elsif (/\S*INDEX (\d+) ([0-9:]+)/i) {
97 my ($idx, $time) = ($1, $self->parse_msf ($2));
98
99 $track->{index}[$idx] = $time;
100 $track->{offset} = $time * $track->{secsize} if $idx == 1;
101
102 } elsif (/\S*PREGAP ([0-9:]+)/i) {
103 $track->{pregap} = $self->parse_msg ($1);
104
105 } elsif (/\S*POSTGAP ([0-9:]+)/i) {
106 $track->{postgap} = $self->parse_msg ($1);
107
108 } else {
109 warn "unknown .cue directive skipped: $_";
110 }
111 }
112
113 # now go through the tracks array
114 my $prev = undef;
115 for (@tracks) {
116 next unless $_;
117 if ($prev && $prev->{offset} <= $_->{offset}) {
118 $prev->{size} = $_->{offset} - $prev->{offset};
119 }
120 $prev = $_;
121 }
122
123 for (@tracks) {
124 if (defined $_) {
125 $cd->append_track (%$_);
126 } else {
127 # synthesize empty track
128 $cd->append_track (size => 0, mode => "MODE1", secsize => 2048);
129 }
130 }
131 }
132
133 #sub _write {
134 # my ($self, $cd) = @_;
135 #}
136
137 1;
138
139 =back
140
141 =head1 AUTHOR
142
143 Marc Lehmann <pcg@goof.com>
144
145 =cut
146