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;
21 use ID3FS::AudioFile::Mp3;
22 use ID3FS::AudioFile::Ogg;
23 use ID3FS::AudioFile::Flac;
28 my $class=ref($proto) || $proto;
33 my $ext=($path=~/.*\.(.*)/)[0];
34 return undef unless($ext);
39 $self->{audiofile}=ID3FS::AudioFile::Mp3->new($path);
43 $self->{audiofile}=ID3FS::AudioFile::Ogg->new($path);
47 $self->{audiofile}=ID3FS::AudioFile::Flac->new($path);
51 print("$me: $path: Unknown extension: $ext\n");
60 return $self->sanitise($self->stripslashes($self->{audiofile}->artist()));
66 return $self->sanitise($self->stripslashes($self->{audiofile}->album()));
72 return $self->sanitise($self->stripslashes($self->{audiofile}->audiotype()));
77 return undef; # NEXTVERSION
79 # return $self->{audiofile}->haspic();
85 return $self->sanitise($self->stripslashes($self->{audiofile}->v1genre()));
91 my $year=$self->sanitise($self->stripslashes($self->{audiofile}->year()));
92 if(defined($year) && $year =~/(\d{4})/)
102 my @intags=$self->{audiofile}->tags();
104 return() unless(@intags);
105 @intags = grep { defined($_); } @intags;
106 # combine then split on commas
107 # so multiple comma-delimited tags will work
108 @intags=split(/\s*,\s*/, join(', ', @intags));
109 for my $tag (@intags)
111 next unless(length($tag));
112 next unless($tag =~ /\S+/);
113 $tag=$self->sanitise($tag);
114 my ($tagname, $tagval)=($tag, undef);
115 if($tag=~/^([^\/]+)\/(.*)/)
117 ($tagname, $tagval)=($1, $2);
119 push(@outtags, [ $tagname, $tagval ]);
126 my ($self, $text)=@_;
127 $text =~ s/[^[:print:]]//g if(defined($text));
133 my ($self, $text)=@_;
134 $text =~ s/\//-/g if(defined($text));