id3fs-index: update usage and man page
[id3fs.git] / lib / ID3FS / AudioFile / Flac.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::Flac;
18
19 use strict;
20 use warnings;
21 use Audio::FLAC::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     my $flac=Audio::FLAC::Header->new($self->{path});
32     $self->{tags}=$flac->tags();
33     return $self;
34 }
35
36 sub get
37 {
38     my ($self, $tag)=@_;
39     for my $key (keys %{$self->{tags}})
40     {
41         if($key =~ /$tag/i &&
42            defined($self->{tags}->{$key})  &&
43            length($self->{tags}->{$key})   &&
44            $self->{tags}->{$key} =~ /\S+/)
45         {
46             return $self->{tags}->{$key};
47         }
48     }
49     return undef;
50 }
51
52 sub artist    { shift->get("ARTIST"); }
53 sub album     { shift->get("ALBUM");  }
54 sub audiotype { return "flac";        }
55 sub haspic    { return undef;         } # FIXME
56 sub v1genre   { return undef;         } # ID3 only
57 sub year      { shift->get("DATE");   }
58
59 sub tags
60 {
61     my $self=shift;
62     my @tags=();
63     my $tags={};
64     for my $key (keys %{$self->{tags}})
65     {
66         if($key =~ /genre/i &&
67            defined($self->{tags}->{$key})  &&
68            length($self->{tags}->{$key})   &&
69            $self->{tags}->{$key} =~ /\S+/)
70         {
71             push(@tags, $self->{tags}->{$key});
72         }
73     }
74     return(@tags);
75 }
76
77 1;