1 # id3fs - a FUSE-based filesystem for browsing audio metadata
2 # Copyright (C) 2010 Ian Beckwith <ianb@erislabs.net>
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.
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.
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/>.
17 package ID3FS::AudioFile::Mp3;
26 my $class=ref($proto) || $proto;
31 $self->{mp3}=MP3::Tag->new($self->{path});
34 $self->{v1}=$self->{mp3}->{ID3v1} if(exists($self->{mp3}->{ID3v1}));
36 $self->{v2}=$self->{mp3}->{ID3v2} if(exists($self->{mp3}->{ID3v2}));
47 if(defined($self->{v2}))
49 $thing=$self->{v2}->$func();
51 if(defined($self->{v1}) && (!defined($thing) || !length($thing)))
53 $thing=$self->{v1}->$func();
58 sub artist { shift->choose("artist"); }
59 sub album { shift->choose("album"); }
60 # We don't care if year is not set
61 sub year { shift->choose("year"); }
62 sub audiotype { return "mp3"; }
63 sub haspic { return undef; } # NEXTVERSION
69 $genre=$self->{v1}->genre() if(defined($self->{v1}));
76 return() unless(exists($self->{mp3}->{ID3v2}) && defined($self->{mp3}->{ID3v2}));
77 return($self->{mp3}->{ID3v2}->genre());
83 # MP3::Tag->get_tags shows cryptic debug info via print when it finds
84 # an unhandled id3v2 version, in addition to the warning, so use
85 # select to send prints to /dev/null
87 if(open(NULL,">/dev/null"))
91 eval { $self->{mp3}->get_tags; };
92 warn("$self->{path}: $@\n") if($@);