# # Sample usage: # # my $reader = gnump3d::oggtagreader->new( ); # my %tags = $reader->getTags($file); # print "File: $file\n"; # print "Title: " . $tags{'artist'} . "\n"; # # package gnump3d::oggtagreader; # must live in oggtagreader.pm # # Create a new instance of this class. # sub new { my $classname = shift; # What class are we constructing? my $self = {}; # Allocate new memory bless($self, $classname); # Mark it of the right type return $self; } # # Read and return a hash of all the tags found in the given file. # # This is a very simplistic algorithm, which may not work for you. # # sub getTags($) { my($self, $filename ) = (@_); open(OGG, "<$filename" ) or die "can't open $filename: $!"; binmode(OGG); my $buff = ""; read(OGG, $buff, 2048); close( OGG ); my %TAGS = (); $TAGS{'artist'} = getTag( $buff, "artist" ); $TAGS{'title'} = getTag( $buff, "title" ); $TAGS{'album'} = getTag( $buff, "album" ); $TAGS{'comment'} = getTag( $buff, "comment" ); $TAGS{'genre'} = getTag( $buff, "genre" ); $TAGS{'track'} = getTag( $buff, "tracknumber" ); return( %TAGS ); } # # Find a given tag in the buffer read from the file in # our 'getTags' method # sub getTag( $ $ ) { my ( $buff, $tag ) = (@_); $buff =~ s/[[:^print:]]/=/g; if ( $buff =~ /$tag=([^=]+)/i ) { my $value = $1; return( $value ); } return( undef ); } # # End of module # 1;