649b45061ece08b10dd7c6e8c28c8364a2ccccf8
[id3fs.git] / lib / ID3FS / AudioFile / Ogg.pm
1 package ID3FS::AudioFile::Ogg;
2
3 use strict;
4 use warnings;
5 use Ogg::Vorbis::Header;
6
7 sub new
8 {
9     my $proto=shift;
10     my $class=ref($proto) || $proto;
11     my $self={};
12     bless($self,$class);
13
14     $self->{path}=shift;
15     $self->{ogg}=Ogg::Vorbis::Header->new($self->{path});
16     $self->{comments}=[ $self->{ogg}->comment_tags() ];
17     return $self;
18 }
19
20 sub get
21 {
22     my ($self, $tag)=@_;
23     for my $commenttype (@{$self->{comments}})
24     {
25         if($commenttype =~ /$tag/i)
26         {
27             my @comments=$self->{ogg}->comment($commenttype);
28             if(@comments)
29             {
30                 # take first comment with actual contents
31                 while(my $comment=shift @comments)
32                 {
33                     if(defined($comment) &&
34                        length($comment)  &&
35                        $comment =~ /\S+/)
36                     {
37                         $comment =~ s/\//-/g; # drop slashes
38                         return $comment;
39                     }
40                 }
41             }
42         }
43     }
44     return undef;
45 }
46
47 sub artist    { shift->get("Artist"); }
48 sub album     { shift->get("Album");  }
49 sub audiotype { return "ogg";         }
50 sub haspic    { return undef;         } # FIXME
51 sub v1genre   { return undef;         } # ID3 only
52 sub year      { shift->get("Date");   }
53
54 sub tags
55 {
56     my $self=shift;
57     my @comments;
58     for my $commenttype (@{$self->{comments}})
59     {
60         if($commenttype =~ /genre/i)
61         {
62             push(@comments,$self->{ogg}->comment($commenttype));
63         }
64     }
65     return(@comments);
66 }
67
68 1;
69