X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2FID3FS%2FAudioFile.pm;h=394a1c51d48fad7bae7d71276e03a90bc511864c;hb=198047fe7da462f486e7da3a751ecdea8d285750;hp=99d4753553ea8be0502ddcc0d639c78dbae59616;hpb=deaedd5e5b0e61dfc9f2b8a390680f0a6f9c1cd3;p=id3fs.git diff --git a/lib/ID3FS/AudioFile.pm b/lib/ID3FS/AudioFile.pm index 99d4753..394a1c5 100644 --- a/lib/ID3FS/AudioFile.pm +++ b/lib/ID3FS/AudioFile.pm @@ -1,3 +1,19 @@ +# id3fs - a FUSE-based filesystem for browsing audio metadata +# Copyright (C) 2010 Ian Beckwith +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + package ID3FS::AudioFile; use strict; @@ -16,6 +32,7 @@ sub new my $path=shift; my $ext=($path=~/.*\.(.*)/)[0]; return undef unless($ext); + my $me=shift; $ext=lc($ext); if($ext eq "mp3") { @@ -31,7 +48,7 @@ sub new } else { - print("Unknown extension: $ext\n"); + print("$me: $path: Unknown extension: $ext\n"); return undef; } return $self; @@ -71,10 +88,8 @@ sub v1genre sub year { my $self=shift; - my $year=($self->sanitise( - $self->stripslashes( - $self->{audiofile}->year()))); - if($year =~/(\d{4})/) + my $year=$self->sanitise($self->stripslashes($self->{audiofile}->year())); + if(defined($year) && $year =~/(\d{4})/) { $year=$1; } @@ -84,34 +99,26 @@ sub year sub tags { my $self=shift; - my @tags=$self->{audiofile}->tags(); - return({}) unless(@tags); - my $tags={}; - if(@tags) + my @intags=$self->{audiofile}->tags(); + my @outtags=(); + return() unless(@intags); + @intags = grep { defined($_); } @intags; + # combine then split on commas + # so multiple comma-delimited tags will work + @intags=split(/\s*,\s*/, join(', ', @intags)); + for my $tag (@intags) { - @tags = grep { defined($_); } @tags; - # combine then split on commas - # so multiple comma-delimited tags will work - @tags=split(/\s*,\s*/, join(', ', @tags)); - for my $tag (@tags) + next unless(length($tag)); + next unless($tag =~ /\S+/); + $tag=$self->sanitise($tag); + my ($tagname, $tagval)=($tag, undef); + if($tag=~/^([^\/]+)\/(.*)/) { - next unless(length($tag)); - next unless($tag =~ /\S+/); - $tag=$self->sanitise($tag); - - if($tag=~/([^\/]+)\/(.*)/) - { - my $tagname = $1; - my $tagval = $self->stripslashes($2); - $tags->{$tagname}=$tagval; - } - else - { - $tags->{$tag}=undef; - } + ($tagname, $tagval)=($1, $2); } + push(@outtags, [ $tagname, $tagval ]); } - return $tags; + return @outtags; } sub sanitise