ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-CD/lib/Convert/CD/TOCFile.pm
Revision: 1.5
Committed: Thu Mar 3 17:49:58 2005 UTC (21 years, 6 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 =head1 NAME
2
3 Convert::CD::TOCFile - base class to represent TOC files.
4
5 =head1 SYNOPSIS
6
7 use Convert::CD::TOCFile;
8
9 # to be done
10
11 =head1 DESCRIPTION
12
13 A TOCFile object is used to represent file-format-specific information
14 about an image, such as image or track filenames and read/write
15 functionality for toc files.
16
17 =head2 Convert:CD::TOCFile METHODS
18
19 =over 4
20
21 =cut
22
23 package Convert::CD::TOCFile;
24
25 $VERSION = 0.01;
26
27 use File::Spec;
28 use Carp;
29
30 use Convert::CD;
31
32 use base Convert::CD::TOCFile;
33
34 =item Convert::CD::TOCFile->autodetect (path)
35
36 Try to autodetect the type of image (or tocfile) identified by C<path>. Returns
37 a list of TOCFile-Classes to try.
38
39 =cut
40
41 sub autodetect {
42 my ($self, $path) = @_;
43 my @r;
44
45 # shouldn't use ending... but Class->autodetect.
46
47 #push @r, Convert::CD::Toc
48 # if $self->find_tocfile ("toc", "TOC", "Toc");
49
50 #push @r, Convert::CD::Ccd
51 # if $self->find_tocfile ("ccd", "CCD", "Ccd");
52
53 push @r, Convert::CD::Cue
54 if $self->find_tocfile ("cue", "CUE", "Cue");
55
56 #push @r, Convert::CD::Nrg # bad
57 # if $self->find_tocfile ("nrg", "NRG", "Nrg");
58
59 push @r, Convert::CD::Analyze;
60
61 @r;
62 }
63
64 =item new param => value...
65
66 Create a new Convert::CD::TOCFile object.
67
68 Parameters:
69
70 path the base image filename
71
72 =cut
73
74 sub new {
75 my $class = shift;
76 my $self = bless { @_, }, $class;
77
78 $self;
79 }
80
81 =item $toc->find_tocfile suffixes..
82
83 Try to find a tocfile by probing the given suffixes.
84
85 =cut
86
87 sub find_tocfile {
88 my ($self, @ext) = @_;
89
90 my $stem = $self->{path};
91
92 $stem =~ s/\.\S{2,4}$//;
93
94 for (@ext) {
95 return "$stem.$_" if -f "$stem.$_";
96 }
97
98 ();
99 }
100
101 =item $cd = $toc->read
102
103 Read the TOC file, returns a new Convert::CD object.
104
105 =item $toc->write ($cd)
106
107 Write the TOC File using the information in the given Convert::CD object.
108
109 =cut
110
111 sub read {
112 my ($self) = @_;
113
114 my $cd = new Convert::CD path => $self->{path}
115 or croak "unable to create a new Convert::CD object";
116
117 $self->_read ($cd);
118
119 $cd;
120 }
121
122 sub write {
123 my ($self, $cd) = @_;
124
125 $self->_write ($cd);
126 }
127
128 # abstract methods
129 sub _read {
130 my ($self, $cd) = @_;
131
132 croak sprintf "reading %s toc files is not supported", ref $self;
133 }
134
135 sub _write {
136 my ($self, $cd) = @_;
137
138 croak sprintf "writing %s toc files is not supported", ref $self;
139 }
140
141 =item $msf = Convert::CD::TOCFile->parse_msf ($string)
142
143 Parses a time and returns it as a frame number (can be negative if the
144 string contains a leading minus).
145
146 Returns C<undef> on error.
147
148 =cut
149
150 sub parse_msf {
151 $_[1] =~ /^(-?\d+):(\d+):(\d+)$/
152 or return undef;
153 ($1 * 60 + $2) * 75 + $3;
154 }
155
156 1;
157
158 =back
159
160 =head1 AUTHOR
161
162 Marc Lehmann <schmorp@schmorp.de>
163
164 =cut
165