remove debug code
[id3fs.git] / lib / ID3FS / File / Ogg.pm
1 package ID3FS::File::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     return $self;
17 }
18
19 sub get
20 {
21     my ($self, $tag, $verbose)=@_;
22     my @comments=$self->{ogg}->comment($tag);
23     if(@comments)
24     {
25         # take first comment with actual contents
26         while(my $comment=shift @comments)
27         {
28             if(defined($comment) &&
29                length($comment)  &&
30                $comment =~ /\S+/)
31             {
32                 $comment =~ s/\//-/g; # drop slashes
33                 return $comment;
34             }
35         }
36     }
37     warn("$self->{path}: no $tag defined in Ogg comments\n") if($verbose);
38     return undef;
39 }
40
41 sub artist    { shift->get("Artist", 1); }
42 sub album     { shift->get("Album", 1);  }
43 sub audiotype { return "ogg";            }
44 sub haspic    { return undef;            } # FIXME
45 sub v1genre   { return undef;            } # ID3 only
46
47 # We don't care if year is not set
48 sub year
49 {
50     my ($self)=@_;
51     my $date=shift->get("Date", 0);
52     return undef unless($date);
53     if($date =~/(\d\d\d\d)/)
54     {
55         $date=$1;
56     }
57     return $date;
58 }
59
60 sub tags
61 {
62     my $self=shift;
63     my @comments=$self->{ogg}->comment("Genre");
64     my $tags={};
65     if(@comments)
66     {
67         # filter for useful comments
68         @comments= grep { defined($_); } @comments;
69         @comments= grep { length($_); }  @comments;
70         @comments= grep { /\S+/; }       @comments;
71         for my $comment (@comments)
72         {
73             if($comment=~/([^\/]+)\/(.*)/)
74             {
75                 my $tagname=$1;
76                 my $tagval=$2;
77                 $tagval=~s/\//-/g;
78                 $tags->{$tagname}=$tagval;
79             }
80             else
81             {
82                 $tags->{$comment}=undef;
83             }
84         }
85     }
86     return $tags;
87 }
88
89 1;
90