source: trunk/gsdl/perllib/plugins/OggVorbisPlug.pm@ 9853

Last change on this file since 9853 was 9853, checked in by kjdon, 19 years ago

fixed up maxdocs - now pass an extra parameter to the read function

  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
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
29package OggVorbisPlug;
30
31
32use UnknownPlug;
33use Ogg::Vorbis::Header::PurePerl;
34
35
36sub BEGIN {
37 @ISA = ('UnknownPlug');
38}
39
40
41my $arguments =
42 [ { 'name' => "process_exp",
43 'desc' => "{BasPlug.process_exp}",
44 'type' => "string",
45 'deft' => &get_default_process_exp(),
46 'reqd' => "no" },
47 { 'name' => "add_technical_metadata",
48 'desc' => "{OggVorbisPlug.add_technical_metadata}",
49 'type' => "flag",
50 'deft' => "" } ];
51
52my $options = { 'name' => "OggVorbisPlug",
53 'desc' => "{OggVorbisPlug.desc}",
54 'inherits' => "yes",
55 'args' => $arguments };
56
57
58# This plugin processes exported Ogg Vorbis files with the suffix ".ogg"
59sub get_default_process_exp
60{
61 return q^(?i)(\.ogg)$^;
62}
63
64
65sub new
66{
67 my $class = shift(@_);
68
69 my $self = new UnknownPlug($class, @_);
70 $self->{'plugin_type'} = "OggVorbisPlug";
71
72 if (!parsargv::parse(\@_,
73 q^add_technical_metadata^, \$self->{'add_technical_metadata'},
74 "allow_extra_options")) {
75 die "\nIncorrect options passed to OggVorbisPlug, check your collect.cfg configuration file\n";
76 }
77
78 # To allow for proper inheritance of arguments
79 my $option_list = $self->{'option_list'};
80 push(@{$option_list}, $options);
81
82 return bless $self, $class;
83}
84
85
86sub read
87{
88 my $self = shift (@_);
89 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
90
91 my $outhandle = $self->{'outhandle'};
92
93 # filename is the full pathname of the file
94 my $filename = &util::filename_cat($base_dir, $file);
95 return 0 if $self->{block_exp} ne "" && $filename =~ /$self->{'block_exp'}/;
96 if ($filename !~ /$self->{'process_exp'}/ || !-f $filename) {
97 return undef;
98 }
99
100 # Report that we're processing the file
101 print STDERR "<Processing n='$file' p='OggVorbisPlug'>\n" if ($gli);
102 print $outhandle "OggVorbisPlug: processing $file\n"
103 if ($self->{'verbosity'}) > 1;
104
105 # file is just the name of the file (need to get rid off any leading directory names)
106 $file =~ s/^.*[\/\\]//;
107
108 # create a new index document
109 my $doc_obj = new doc ($filename, "indexed_doc");
110 $doc_obj->set_OIDtype ("incremental"); # this is done to avoid hashing content of file
111
112 # replace spaces in filename with %20 in url for metadata entry
113 my $url = $file;
114 $url =~ s/ /%20/g;
115 # Source (filename) to be consistent with other plugins
116 $doc_obj->add_metadata ($section, "Source", $url);
117
118 # Extract metadata
119 my $ogg = Ogg::Vorbis::Header::PurePerl->new($filename);
120
121 # Comments added to the file
122 foreach my $key ($ogg->comment_tags())
123 {
124 # Convert key to title case
125 my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
126 foreach my $value ($ogg->comment($key))
127 {
128 if (defined $value && $value ne "") {
129 $doc_obj->add_metadata($section, $keytc, $value);
130 }
131 }
132 }
133
134 # Technical data (optional)
135 if ($self->{'add_technical_metadata'}) {
136 foreach my $key (keys %{$ogg->info})
137 {
138 # Convert key to title case
139 my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
140 my $value = $ogg->info->{$key};
141 if (defined $value && $value ne "") {
142 $doc_obj->add_metadata($section, $keytc, $value);
143 }
144 }
145 }
146
147 # srclink
148 $doc_obj->add_metadata ($section, "FileFormat", "OggVorbis");
149 $doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpcollection_/index/assoc/[assocfilepath]/[Source]\">");
150 $doc_obj->add_metadata ($section, "/srclink", "</a>");
151 # srcicon (need to include "ogg.png" in the greenstone images directory
152 $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/images/ogg.png\" title=\"Download\" border=0>");
153
154 # Add the actual file as an associated file
155 $doc_obj->associate_file($filename, $file, "VORBIS", $section);
156
157 # Create an empty text string so we don't break downstream plugins
158 my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}");
159
160 # include any metadata passed in from previous plugins
161 my $section = $doc_obj->get_top_section();
162 $self->extra_metadata ($doc_obj, $section, $metadata);
163
164 # do plugin specific processing of doc_obj
165 return undef unless defined ($self->process (\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj));
166
167 # do any automatic metadata extraction
168 $self->auto_extract_metadata($doc_obj);
169
170 # add an OID
171 $doc_obj->set_OID();
172 $doc_obj->add_text($section, $text);
173
174 # process the document
175 $processor->process($doc_obj);
176
177 $self->{'num_processed'}++;
178 return 1;
179}
180
181
1821;
Note: See TracBrowser for help on using the repository browser.