--- readtags.pm 2005-11-09 03:41:04.000000000 -0800 +++ /usr/share/perl5/gnump3d/readtags.pm 2005-11-09 01:53:20.000000000 -0800 @@ -6,15 +6,16 @@ use strict; use gnump3d::ogginfo; # Pure Perl OGG Vorbis tag parsing. -use gnump3d::oggtagreader; # Local vorbis code +use gnump3d::oggtagreader; # Local vorbis tag code use gnump3d::mp3info; # Local copy of MP3::Info. use gnump3d::mp4info; # Local copy of MP4::Info. use gnump3d::WMA; # Local copy of Audio::WMA +use Audio::FLAC; # Vorbis tag parsing for FLAC files. use vars qw(@ISA @EXPORT); @ISA = 'Exporter'; address@hidden = qw(getMP3Display getMP4Display getWMADisplay getOggDisplay getTags); address@hidden = qw(getMP3Display getMP4Display getWMADisplay getOggDisplay getFLACDisplay getTags); # # Get the meta tags from an MP3 file. @@ -200,6 +201,50 @@ return( %TAGS ); } + +# +# Get the display text for a FLAC file. +# +sub getFLACDisplay($) +{ + my ($file) = (@_); + + my $reader = Audio::FLAC->new($file); + my %TAGS; + + # info + while (my ($key, $v) = each %{$reader->info}) + { + $TAGS{uc($key)} = $v; + } + + + my $comment = gnump3d::oggtagreader->new( ); + my %tags = $comment->getTags($file); + + if ( keys( %tags ) ) + { + $TAGS{'ARTIST'} = $tags{'artist'} || ""; + $TAGS{'COMMENT'}= $tags{'comment'} || ""; + $TAGS{'GENRE'} = $tags{'genre'} || ""; + $TAGS{'TRACK'} = $tags{'track'} || ""; + $TAGS{'ALBUM'} = $tags{'album'} || ""; + $TAGS{'TITLE'} = $tags{'title'} || ""; + } +# This all needs to be changed since it doesn't work with oggtagreader as is. man Audio::FLAC may be of use +# $TAGS{'YEAR'} = $tags{'year'} || ""; +# $TAGS{'SIZE'} = $tags{'size'} || ""; +# if ($TAGS{'LENGTH'}) # Ogg returns in sss format vice mm:ss +# { +# my $s = $TAGS{'LENGTH'} % 60; +# my $m = ($TAGS{'LENGTH'} - $s) / 60; +# $TAGS{'LENGTH'} = sprintf("%d:%02d", $m, $s); +# } + + return( %TAGS ); +} + + sub getTags($) { my ($file) = (@_); my %TAGS; @@ -237,6 +282,11 @@ %TAGS = &getOGGDisplay($file); $TAGS{'SIZE'} = $fstat[7] unless $TAGS{'SIZE'}; } + elsif( $file =~ /flac$/i ) + { + %TAGS = &getFLACDisplay($file); + $TAGS{'SIZE'} = $fstat[7] unless $TAGS{'SIZE'}; + } $TAGS{'MTIME'} = $fstat[9]; $TAGS{'FILENAME'} = $filename;