From: Ian Beckwith Date: Sat, 25 Sep 2010 06:15:40 +0000 (+0100) Subject: ogg support X-Git-Tag: debian/1.0-1~175 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=6a0315290f6553a5139e49a6de10552415c55b13;p=id3fs.git ogg support --- diff --git a/bin/id3fs-index b/bin/id3fs-index index 3dd1227..8fa80b3 100755 --- a/bin/id3fs-index +++ b/bin/id3fs-index @@ -14,7 +14,7 @@ my $verbose=0; my $help=0; my $basedir=undef; my $dbpath=undef; -my @extensions=qw(mp3 flac); # ogg); # FIXME +my @extensions=qw(mp3 flac ogg); Configure(qw(bundling no_ignore_case)); my $optret=GetOptions( diff --git a/lib/ID3FS/File/Ogg.pm b/lib/ID3FS/File/Ogg.pm index 0f664b0..6498a3b 100644 --- a/lib/ID3FS/File/Ogg.pm +++ b/lib/ID3FS/File/Ogg.pm @@ -2,6 +2,7 @@ package ID3FS::File::Ogg; use strict; use warnings; +use Ogg::Vorbis::Header; sub new { @@ -9,10 +10,84 @@ sub new my $class=ref($proto) || $proto; my $self={}; bless($self,$class); - # FIXME - print "OGG UNIMPLEMENTED\n"; + $self->{path}=shift; + $self->{ogg}=Ogg::Vorbis::Header->new($self->{path}); + use Data::Dumper; + # load tags + print Dumper $self->{ogg}->comment_tags; return $self; } +sub get +{ + my ($self, $tag, $verbose)=@_; + my @comments=$self->{ogg}->comment($tag); + if(@comments) + { + # take first comment with actual contents + while(my $comment=shift @comments) + { + if(defined($comment) && + length($comment) && + $comment =~ /\S+/) + { + $comment =~ s/\//-/g; # drop slashes + return $comment; + } + } + } + warn("$self->{path}: no $tag defined in Ogg comments\n") if($verbose); + return undef; +} + +sub artist { shift->get("Artist", 1); } +sub album { shift->get("Album", 1); } +sub audiotype { return "ogg"; } +sub haspic { return undef; } # FIXME +sub v1genre { return undef; } # ID3 only + +# We don't care if year is not set +sub year +{ + my ($self)=@_; + my $date=shift->get("Date", 0); + return undef unless($date); + if($date =~/(\d\d\d\d)/) + { + $date=$1; + } + return $date; +} + +sub tags +{ + my $self=shift; + my @comments=$self->{ogg}->comment("Genre"); + my $tags={}; + if(@comments) + { + # filter for useful comments + @comments= grep { defined($_); } @comments; + @comments= grep { length($_); } @comments; + @comments= grep { /\S+/; } @comments; + for my $comment (@comments) + { + if($comment=~/([^\/]+)\/(.*)/) + { + my $tagname=$1; + my $tagval=$2; + $tagval=~s/\//-/g; + $tags->{$tagname}=$tagval; + } + else + { + $tags->{$comment}=undef; + } + } + } + return $tags; +} + 1; +