/
Header.pm
executable file
·89 lines (60 loc) · 1.65 KB
/
Header.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
=head1 NAME
AudioFile::Info::Ogg::Vorbis::Header - Perl extension to get info from
Ogg Vorbis files.
=head1 DESCRIPTION
Extracts data from an Ogg Vorbis file using the CPAN module
Ogg::Vorbis::Header.
See L<AudioFile::Info> for more details.
=cut
package AudioFile::Info::Ogg::Vorbis::Header;
use 5.006;
use strict;
use warnings;
use Carp;
use Ogg::Vorbis::Header;
# nasty Inline kludge
# needed as this module is never "used", only "required"
require Inline;
Inline->init;
our $VERSION = '1.8.1';
my %data = (artist => 'ARTIST',
title => 'TITLE',
album => 'ALBUM',
track => 'TRACKNUMBER',
year => 'DATE',
genre => 'GENRE');
sub new {
my $class = shift;
my $file = shift;
my $obj = Ogg::Vorbis::Header->new($file);
bless { obj => $obj }, $class;
}
sub DESTROY {}
sub AUTOLOAD {
our $AUTOLOAD;
my ($pkg, $sub) = $AUTOLOAD =~ /(.*)::(\w+)/;
croak "Invalid attribute '$sub'" unless $data{$sub};
if ($_[1]) {
my @matches = grep { $_ eq $data{$sub} } $_[0]->{obj}->comment_tags;
if (@matches) {
$_[0]->{obj}->edit_comment($data{$sub}, $_[1]);
} else {
$_[0]->{obj}->add_comments($data{$sub}, $_[1]);
}
$_[0]->{obj}->write_vorbis;
}
return ($_[0]->{obj}->comment($data{$sub}))[0];
}
1;
__END__
=head1 METHODS
=head2 new
Creates a new object of class AudioFile::Info::Ogg::Vorbis::Header. Usually
called by AudioFile::Info::new.
=head1 AUTHOR
Dave Cross, E<lt>dave@dave.org.ukE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2003 by Dave Cross
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut