| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MP3::Tag; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
################ |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# provides a general interface for different modules, which can read tags |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# at the moment MP3::Tag works with MP3::TAG::ID3v1 and MP3::TAG::ID3v2 |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
501
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
10
|
1
|
|
|
1
|
|
464
|
use MP3::TAG::ID3v1; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
11
|
1
|
|
|
1
|
|
611
|
use MP3::TAG::ID3v2; |
|
|
1
|
|
|
|
|
16
|
|
|
|
1
|
|
|
|
|
31
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
732
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION="0.1"; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=pod |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Tag - Perl extension reading tags of mp3 files |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Tag; |
|
25
|
|
|
|
|
|
|
$mp3 = MP3::Tag->new($filename); |
|
26
|
|
|
|
|
|
|
$mp3->getTags; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if (exists $mp3->{ID3v1}) { |
|
29
|
|
|
|
|
|
|
$id3v1 = $mp3->{ID3v1}; |
|
30
|
|
|
|
|
|
|
print $id3v1->song; |
|
31
|
|
|
|
|
|
|
... |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if (exists $mp3->{ID3v2}) { |
|
35
|
|
|
|
|
|
|
($name, $info) = $mp3->{ID3v2}->getFrame("TIT2"); |
|
36
|
|
|
|
|
|
|
... |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 AUTHOR |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Thomas Geffert, thg@users.sourceforge.net |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Tag is a wrapper module to read different tags of mp3 files. |
|
46
|
|
|
|
|
|
|
It provides an easy way to access the functions of seperate moduls |
|
47
|
|
|
|
|
|
|
which do the handling of reading/writing the tags itself. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
At the moment MP3::TAG::ID3v1 and MP3::TAG::ID3v2 are supported. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
!! As this is only a beta version, it is very likely that the design |
|
52
|
|
|
|
|
|
|
!! of this wrapper module will change soon !! |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item new |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$mp3 = MP3::TAG->new($filename); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Creates a mp3-object, which can be used to retrieve/set |
|
61
|
|
|
|
|
|
|
different tags. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub new { |
|
66
|
2
|
|
|
2
|
1
|
41
|
my $class = shift; |
|
67
|
2
|
|
|
|
|
8
|
my $self={filename=>shift}; |
|
68
|
2
|
50
|
|
|
|
33
|
return undef unless -f $self->{filename}; |
|
69
|
2
|
|
|
|
|
5
|
bless $self, $class; |
|
70
|
2
|
|
|
|
|
6
|
return $self; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=pod |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item getTags |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
@tags = $mp3->getTags; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Checks which tags can be found in the mp3-object. It returns |
|
80
|
|
|
|
|
|
|
a list @tags which contains strings identifying the found tags. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Each found tag can be accessed then with $mp3->{tagname} . |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Use the information found in MP3::TAG::ID3v1 and MP3::TAG::ID3v2 |
|
85
|
|
|
|
|
|
|
to see what you can do with the tags. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
################ tag subs |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub getTags { |
|
92
|
2
|
|
|
2
|
1
|
9
|
my $self = shift; |
|
93
|
2
|
|
|
|
|
3
|
my (@IDs, $ref); |
|
94
|
2
|
50
|
|
|
|
7
|
if ($self->open()) { |
|
95
|
2
|
50
|
|
|
|
13
|
if (defined ($ref = MP3::TAG::ID3v2->new($self))) { |
|
96
|
2
|
|
|
|
|
3
|
$self->{ID3v2} = $ref; |
|
97
|
2
|
|
|
|
|
4
|
push @IDs, "ID3v2"; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
2
|
50
|
|
|
|
14
|
if(defined ($ref = MP3::TAG::ID3v1->new($self))) { |
|
100
|
2
|
|
|
|
|
3
|
$self->{ID3v1} = $ref; |
|
101
|
2
|
|
|
|
|
2
|
push @IDs, "ID3v1"; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
2
|
|
|
|
|
6
|
return @IDs; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
|
|
|
|
0
|
return undef; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=pod |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item newTag |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$mp3->newTag($tagname); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Creates a new tag of the given type $tagname. You |
|
115
|
|
|
|
|
|
|
can access it then with $mp3->{$tagname} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub newTag { |
|
120
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
121
|
0
|
|
|
|
|
0
|
my $whichTag = shift; |
|
122
|
0
|
0
|
|
|
|
0
|
if ($whichTag eq "ID3v1") { |
|
|
|
0
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
0
|
$self->{ID3v1}= MP3::TAG::ID3v1->new($self,1); |
|
124
|
|
|
|
|
|
|
} elsif ($whichTag eq "ID3v2") { |
|
125
|
0
|
|
|
|
|
0
|
$self->{ID3v2}= MP3::TAG::ID3v2->new($self,1); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=pod |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item genres |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
@allgenres = $mp3->genres; |
|
134
|
|
|
|
|
|
|
$genreName = $mp3->genres($genreID); |
|
135
|
|
|
|
|
|
|
$genreID = $mp3->genres($genreName); |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Returns a list of all genres, or the according name or id to |
|
138
|
|
|
|
|
|
|
a given id or name. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This function is only a shortcut to MP3::TAG::ID3v1->genres. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub genres { |
|
145
|
|
|
|
|
|
|
# returns all genres, or if a parameter is given, the according genre |
|
146
|
0
|
|
|
0
|
1
|
0
|
return MP3::ID3v1::genres(shift); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
################ file subs |
|
150
|
|
|
|
|
|
|
sub open { |
|
151
|
6
|
|
|
6
|
0
|
9
|
my $self=shift; |
|
152
|
6
|
|
100
|
|
|
18
|
my $mode= shift || "<"; |
|
153
|
6
|
50
|
|
|
|
25
|
unless (exists $self->{FH}) { |
|
154
|
6
|
50
|
|
|
|
176
|
if (open (FH, $mode . $self->{filename})) { |
|
155
|
6
|
|
|
|
|
18
|
$self->{FH} = *FH; |
|
156
|
|
|
|
|
|
|
} else { |
|
157
|
0
|
|
|
|
|
0
|
warn "Open $self->{filename} failed: $!\n"; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
6
|
|
|
|
|
23
|
return exists $self->{FH}; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub close { |
|
164
|
4
|
|
|
4
|
0
|
5
|
my $self=shift; |
|
165
|
4
|
50
|
|
|
|
12
|
if (exists $self->{FH}) { |
|
166
|
4
|
|
|
|
|
81
|
close $self->{FH}; |
|
167
|
4
|
|
|
|
|
14
|
delete $self->{FH}; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub write { |
|
172
|
12
|
|
|
12
|
0
|
18
|
my ($self, $data) = @_; |
|
173
|
12
|
50
|
|
|
|
26
|
if (exists $self->{FH}) { |
|
174
|
12
|
|
|
|
|
10
|
print {$self->{FH}} $data; |
|
|
12
|
|
|
|
|
60
|
|
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub truncate { |
|
179
|
0
|
|
|
0
|
0
|
0
|
my ($self, $length) = @_; |
|
180
|
0
|
0
|
|
|
|
0
|
if ($length<0) { |
|
181
|
0
|
|
|
|
|
0
|
my @stat = stat $self->{FH}; |
|
182
|
0
|
|
|
|
|
0
|
$length = $stat[7] + $length; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
0
|
0
|
|
|
|
0
|
if (exists $self->{FH}) { |
|
185
|
0
|
|
|
|
|
0
|
truncate $self->{FH}, $length; |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub seek { |
|
190
|
8
|
|
|
8
|
0
|
10
|
my ($self, $pos, $whence)=@_; |
|
191
|
8
|
50
|
|
|
|
122
|
$self->open unless exists $self->{FH}; |
|
192
|
8
|
|
|
|
|
50
|
seek $self->{FH}, $pos, $whence; |
|
193
|
|
|
|
|
|
|
} |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub tell { |
|
196
|
0
|
|
|
0
|
0
|
0
|
my ($self, $pos, $whence)=@_; |
|
197
|
0
|
0
|
|
|
|
0
|
return undef unless exists $self->{FH}; |
|
198
|
0
|
|
|
|
|
0
|
return tell $self->{FH}; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub read { |
|
202
|
8
|
|
|
8
|
0
|
11
|
my ($self, $buf_, $length) = @_; |
|
203
|
8
|
50
|
|
|
|
13
|
$self->open unless exists $self->{FH}; |
|
204
|
8
|
|
|
|
|
79
|
return read $self->{FH}, $$buf_, $length; |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub isOpen { |
|
208
|
0
|
|
|
0
|
0
|
|
return exists shift->{FH}; |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub DESTROY { |
|
213
|
0
|
|
|
0
|
|
|
my $self=shift; |
|
214
|
0
|
0
|
|
|
|
|
if (exists $self->{FH}) { |
|
215
|
0
|
|
|
|
|
|
$self->close; |
|
216
|
|
|
|
|
|
|
} |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
|
221
|
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=pod |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
MP3::TAG::ID3v1, MP3::TAG::ID3v2 |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |