# # -*- Perl -*- # ogg.pl (C) 2006 alexander@oelzant.priv.at # using code from mp3.pl which is ... # Copyright (C) 2002 Luc@2113.ch , # 2002 2113.ch , # 2003-2004 Namazu Project All rights reserved , # This is free software with ABSOLUTELY NO WARRANTY. # # 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 versions 2, 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA # # This file must be encoded in EUC-JP encoding # package ogg; use strict; require 'util.pl'; require 'gfilter.pl'; my $rpmpath = undef; sub mediatype() { return ('application/ogg'); } sub status() { return 'yes'; } sub recursive() { return 0; } sub pre_codeconv() { return 0; } sub post_codeconv () { return 0; } sub add_magic ($) { my ($magic) = @_; $magic->addMagicEntry("0\tstring\tOggS\tapplication/ogg"); return; } sub filter($$$$$) { my $data1 = ""; my $data2 = ""; my ($orig_cfile, $contref, $weighted_str, $headings, $fields) = @_; my $cfile = defined $orig_cfile ? $$orig_cfile : ''; my $header = substr($$contref, 0, 4); if ($cfile =~ /(\d\d\d\d-\d\d-\d\d)_(\d\d)_(\d\d)_(.*).ogg/) { my $title=$3; $title =~ s/_/ /g; $data1 .= "Date: $1\n"; $data1 .= "Time: $2:$3\n"; $data1 .= "Title: $4\n"; } else { $data1 .= "Title: $cfile\n"; } unless ($header =~ /OggS/) { util::vprint("Couldn't find OggS tag\n"); $$contref=$data1; return undef; } util::vprint("Processing ogg file ...\n"); my ($i,$len,$tot,$lacing,$ilacing,$offset,$status); $tot=length($$contref); $i=0; # an ogg page has a 27 byte header # (3rd byte of the 7th word is the number of packets) # and the text information is in the first vorbis stream packet # of the second page ... # so we have to skip one ogg page, ... # the \xXXvorbis packet we want has \xXX type 3 :) my $info=0; # marker for info pack OGGS: while (($i+27 < $tot) && substr($$contref, $i, 4) =~ /OggS/ && (($lacing)=unpack("C",substr($$contref, $i+26,1)))) { $status="page with $lacing packets at $i: "; $ilacing=0; $i+=27; $offset=$i+$lacing; while (($offset < $tot) && $ilacing < $lacing) { $len=unpack("C",substr($$contref, $i+$ilacing,1)); $ilacing++; my $packet=substr($$contref, $offset, $len); if ($packet =~ /^\x03vorbis/ || $info == 1) { $status .= "I$len"; $info=1; $data2 .= $packet; if ($len < 255) { print "\n"; last OGGS; } } else { $status .= "_$len"; } #my $packet=substr($$contref, $offset, $len); $offset+=$len; } util::vprint("$status\n"); $i=$offset; } util::vprint("$status\n"); # $len=unpack("I",substr($$contref, $i, 4)))) { # the data packet consists of 7 bytes header, 1 byte encoder info, # 4 bytes network order "number of items" and a list of # 4 bytes network order length, data if ($data2) { my $item; my $title=""; $i=7; $len=unpack("V",substr($data2, $i, 4)); $i+=4; $data1 .= "Encoder: " . substr($data2, $i, $len) . "\n"; $i+=$len; my $items=unpack("V",substr($data2, $i, 4)); print "header: $len, number of items: $items\n"; $i+=4; while ($items-- && defined($len=unpack("V",substr($data2, $i, 4)))) { $i+=4; my $item=substr($data2, $i, $len); $item =~ s/=/: /; if ($item =~ /^next:/) { $title="$item\n"; $title =~ s/^next/title/; } elsif ($item =~ /^title:/) { $title="$item\n"; } elsif ($item =~ /^:/) { $title.="Comment$item\n"; } else { $data1 .= "$item\n"; } $i+=$len; } $data1=$title.$data1; print $data1; } else { $data1 .= (substr($$contref,0,1000)); $data1 =~ s/[^[:print:]]/ /msg; $data1 =~ s/ / /g; } codeconv::toeuc(\$data1); $$contref = $data1; return undef; # TODO: there should probably be some kind of weighting function # like the one in the mp3 filter } sub get_title($$$) { my ($content, $weighted_str, $fields) = @_; if ($content =~ /Songname: (.*)/) { my $tmp = $1; $fields->{'title'} = $tmp; }else { $content =~ /Filename: (.*)/; my $tmp = $1; $fields->{'title'} = $tmp; } my $weight = $conf::Weight{'html'}->{'title'}; $$weighted_str .= "\x7f$weight\x7f$fields->{'title'}\x7f/$weight\x7f\n"; } sub get_author($$) { my ($content, $fields) = @_; if ($content =~ /Artist: (.*)/) { my $tmp = $1; $fields->{'author'} = $tmp; } } sub get_album($$) { my ($content, $fields) = @_; if ($content =~ /Album: (.*)/) { my $tmp = $1; $fields->{'album'} = $tmp; } } sub get_summary($$) { my ($content, $fields) = @_; $fields->{'summary'} = $content; } 1;