add copyright/license headers
[id3fs.git] / lib / ID3FS / AudioFile / Ogg.pm
1 # id3fs - a FUSE-based filesystem for browsing audio metadata
2 # Copyright (C) 2010  Ian Beckwith <ianb@erislabs.net>
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 package ID3FS::AudioFile::Ogg;
18
19 use strict;
20 use warnings;
21 use Ogg::Vorbis::Header;
22
23 sub new
24 {
25     my $proto=shift;
26     my $class=ref($proto) || $proto;
27     my $self={};
28     bless($self,$class);
29
30     $self->{path}=shift;
31     $self->{ogg}=Ogg::Vorbis::Header->new($self->{path});
32     $self->{comments}=[ $self->{ogg}->comment_tags() ];
33     return $self;
34 }
35
36 sub get
37 {
38     my ($self, $tag)=@_;
39     for my $commenttype (@{$self->{comments}})
40     {
41         if($commenttype =~ /$tag/i)
42         {
43             my @comments=$self->{ogg}->comment($commenttype);
44             if(@comments)
45             {
46                 # take first comment with actual contents
47                 while(my $comment=shift @comments)
48                 {
49                     if(defined($comment) &&
50                        length($comment)  &&
51                        $comment =~ /\S+/)
52                     {
53                         $comment =~ s/\//-/g; # drop slashes
54                         return $comment;
55                     }
56                 }
57             }
58         }
59     }
60     return undef;
61 }
62
63 sub artist    { shift->get("Artist"); }
64 sub album     { shift->get("Album");  }
65 sub audiotype { return "ogg";         }
66 sub haspic    { return undef;         } # FIXME
67 sub v1genre   { return undef;         } # ID3 only
68 sub year      { shift->get("Date");   }
69
70 sub tags
71 {
72     my $self=shift;
73     my @comments;
74     for my $commenttype (@{$self->{comments}})
75     {
76         if($commenttype =~ /genre/i)
77         {
78             push(@comments,$self->{ogg}->comment($commenttype));
79         }
80     }
81     return(@comments);
82 }
83
84 1;
85