[7911] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # OggVorbisPlug.pm -- A plugin for Ogg Vorbis audio files
|
---|
| 4 | #
|
---|
| 5 | # Original code by Christy Kuo
|
---|
| 6 | #
|
---|
| 7 | # A component of the Greenstone digital library software
|
---|
| 8 | # from the New Zealand Digital Library Project at the
|
---|
| 9 | # University of Waikato, New Zealand.
|
---|
| 10 | #
|
---|
| 11 | # Copyright 1999-2004 New Zealand Digital Library Project
|
---|
| 12 | #
|
---|
| 13 | # This program is free software; you can redistribute it and/or modify
|
---|
| 14 | # it under the terms of the GNU General Public License as published by
|
---|
| 15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | # (at your option) any later version.
|
---|
| 17 | #
|
---|
| 18 | # This program is distributed in the hope that it will be useful,
|
---|
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 21 | # GNU General Public License for more details.
|
---|
| 22 | #
|
---|
| 23 | # You should have received a copy of the GNU General Public License
|
---|
| 24 | # along with this program; if not, write to the Free Software
|
---|
| 25 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 26 | #
|
---|
| 27 | ###########################################################################
|
---|
| 28 |
|
---|
| 29 | package OggVorbisPlug;
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | use UnknownPlug;
|
---|
| 33 | use Ogg::Vorbis::Header::PurePerl;
|
---|
| 34 |
|
---|
[10254] | 35 | use strict;
|
---|
| 36 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[7911] | 37 |
|
---|
| 38 | sub BEGIN {
|
---|
[10218] | 39 | @OggVorbisPlug::ISA = ('UnknownPlug');
|
---|
[7911] | 40 | }
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | my $arguments =
|
---|
| 44 | [ { 'name' => "process_exp",
|
---|
| 45 | 'desc' => "{BasPlug.process_exp}",
|
---|
| 46 | 'type' => "string",
|
---|
| 47 | 'deft' => &get_default_process_exp(),
|
---|
| 48 | 'reqd' => "no" },
|
---|
| 49 | { 'name' => "add_technical_metadata",
|
---|
| 50 | 'desc' => "{OggVorbisPlug.add_technical_metadata}",
|
---|
| 51 | 'type' => "flag",
|
---|
| 52 | 'deft' => "" } ];
|
---|
| 53 |
|
---|
| 54 | my $options = { 'name' => "OggVorbisPlug",
|
---|
| 55 | 'desc' => "{OggVorbisPlug.desc}",
|
---|
| 56 | 'inherits' => "yes",
|
---|
[11676] | 57 | 'abstract' => "no",
|
---|
[7911] | 58 | 'args' => $arguments };
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | # This plugin processes exported Ogg Vorbis files with the suffix ".ogg"
|
---|
| 62 | sub get_default_process_exp
|
---|
| 63 | {
|
---|
| 64 | return q^(?i)(\.ogg)$^;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | sub new
|
---|
| 69 | {
|
---|
[10218] | 70 | my ($class) = shift(@_);
|
---|
| 71 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 72 | push(@$pluginlist, $class);
|
---|
| 73 |
|
---|
| 74 | if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
|
---|
| 75 | if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
|
---|
| 76 |
|
---|
| 77 | my $self = (defined $hashArgOptLists)? new UnknownPlug($pluginlist,$inputargs,$hashArgOptLists): new UnknownPlug($pluginlist,$inputargs);
|
---|
| 78 |
|
---|
[7911] | 79 | return bless $self, $class;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | sub read
|
---|
| 84 | {
|
---|
| 85 | my $self = shift (@_);
|
---|
[9853] | 86 | my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
|
---|
[7911] | 87 |
|
---|
| 88 | my $outhandle = $self->{'outhandle'};
|
---|
| 89 |
|
---|
[11090] | 90 | #check process and block exps, smart block, etc
|
---|
| 91 | my ($block_status,$filename) = $self->read_block(@_);
|
---|
| 92 | return $block_status if ((!defined $block_status) || ($block_status==0));
|
---|
[7911] | 93 |
|
---|
[11090] | 94 | # Report that we're processing the file
|
---|
[7911] | 95 | print STDERR "<Processing n='$file' p='OggVorbisPlug'>\n" if ($gli);
|
---|
| 96 | print $outhandle "OggVorbisPlug: processing $file\n"
|
---|
| 97 | if ($self->{'verbosity'}) > 1;
|
---|
| 98 |
|
---|
| 99 | # file is just the name of the file (need to get rid off any leading directory names)
|
---|
| 100 | $file =~ s/^.*[\/\\]//;
|
---|
| 101 |
|
---|
| 102 | # create a new index document
|
---|
| 103 | my $doc_obj = new doc ($filename, "indexed_doc");
|
---|
| 104 | $doc_obj->set_OIDtype ("incremental"); # this is done to avoid hashing content of file
|
---|
[10254] | 105 | my $section = $doc_obj->get_top_section();
|
---|
| 106 |
|
---|
[7911] | 107 | # replace spaces in filename with %20 in url for metadata entry
|
---|
| 108 | my $url = $file;
|
---|
| 109 | $url =~ s/ /%20/g;
|
---|
| 110 | # Source (filename) to be consistent with other plugins
|
---|
| 111 | $doc_obj->add_metadata ($section, "Source", $url);
|
---|
| 112 |
|
---|
| 113 | # Extract metadata
|
---|
| 114 | my $ogg = Ogg::Vorbis::Header::PurePerl->new($filename);
|
---|
| 115 |
|
---|
| 116 | # Comments added to the file
|
---|
| 117 | foreach my $key ($ogg->comment_tags())
|
---|
| 118 | {
|
---|
| 119 | # Convert key to title case
|
---|
| 120 | my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
|
---|
| 121 | foreach my $value ($ogg->comment($key))
|
---|
| 122 | {
|
---|
| 123 | if (defined $value && $value ne "") {
|
---|
| 124 | $doc_obj->add_metadata($section, $keytc, $value);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | # Technical data (optional)
|
---|
| 130 | if ($self->{'add_technical_metadata'}) {
|
---|
| 131 | foreach my $key (keys %{$ogg->info})
|
---|
| 132 | {
|
---|
| 133 | # Convert key to title case
|
---|
| 134 | my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
|
---|
| 135 | my $value = $ogg->info->{$key};
|
---|
| 136 | if (defined $value && $value ne "") {
|
---|
| 137 | $doc_obj->add_metadata($section, $keytc, $value);
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | # srclink
|
---|
[8138] | 143 | $doc_obj->add_metadata ($section, "FileFormat", "OggVorbis");
|
---|
[11834] | 144 | $doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Source]\">");
|
---|
[7911] | 145 | $doc_obj->add_metadata ($section, "/srclink", "</a>");
|
---|
[11193] | 146 | # srcicon (need to include "iogg.gif" in the greenstone images directory
|
---|
| 147 | $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/images/iogg.gif\" title=\"Download\" border=0>");
|
---|
[7911] | 148 |
|
---|
| 149 | # Add the actual file as an associated file
|
---|
| 150 | $doc_obj->associate_file($filename, $file, "VORBIS", $section);
|
---|
| 151 |
|
---|
| 152 | # Create an empty text string so we don't break downstream plugins
|
---|
| 153 | my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
|
---|
| 154 |
|
---|
| 155 | # include any metadata passed in from previous plugins
|
---|
| 156 | $self->extra_metadata ($doc_obj, $section, $metadata);
|
---|
| 157 |
|
---|
| 158 | # do plugin specific processing of doc_obj
|
---|
| 159 | return undef unless defined ($self->process (\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj));
|
---|
| 160 |
|
---|
| 161 | # do any automatic metadata extraction
|
---|
| 162 | $self->auto_extract_metadata($doc_obj);
|
---|
| 163 |
|
---|
| 164 | # add an OID
|
---|
| 165 | $doc_obj->set_OID();
|
---|
| 166 | $doc_obj->add_text($section, $text);
|
---|
| 167 |
|
---|
| 168 | # process the document
|
---|
| 169 | $processor->process($doc_obj);
|
---|
| 170 |
|
---|
| 171 | $self->{'num_processed'}++;
|
---|
| 172 | return 1;
|
---|
| 173 | }
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 | 1;
|
---|