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

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

added 'use strict' to all plugins, and made modifications (mostly adding 'my') to make them compile

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