This is a sleazy module for reading OGG Vorbis tags from files, without using C or libvorbis-perl.

 I wanted something standalone for my MP3/OGG streamer.

# # 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;

In reply to OGG Vorbis tag parsing in pure perl by skx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.