source: gsdl/trunk/perllib/plugins/OggVorbisPlugin.pm@ 15872

Last change on this file since 15872 was 15872, checked in by kjdon, 16 years ago

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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 OggVorbisPlugin;
30
31
32use BasePlugin;
33use Ogg::Vorbis::Header::PurePerl;
34
35use strict;
36no strict 'refs'; # allow filehandles to be variables and viceversa
37no strict 'subs';
38
39sub BEGIN {
40 @OggVorbisPlugin::ISA = ('BasePlugin');
41}
42
43
44my $arguments =
45 [ { 'name' => "process_exp",
46 'desc' => "{BasePlugin.process_exp}",
47 'type' => "string",
48 'deft' => &get_default_process_exp(),
49 'reqd' => "no" },
50 { 'name' => "add_technical_metadata",
51 'desc' => "{OggVorbisPlugin.add_technical_metadata}",
52 'type' => "flag",
53 'deft' => "" } ];
54
55my $options = { 'name' => "OggVorbisPlugin",
56 'desc' => "{OggVorbisPlugin.desc}",
57 'inherits' => "yes",
58 'abstract' => "no",
59 'args' => $arguments };
60
61
62# This plugin processes exported Ogg Vorbis files with the suffix ".ogg"
63sub get_default_process_exp
64{
65 return q^(?i)(\.ogg)$^;
66}
67
68
69sub new
70{
71 my ($class) = shift(@_);
72 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
73 push(@$pluginlist, $class);
74
75 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
76 push(@{$hashArgOptLists->{"OptList"}},$options);
77
78 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
79
80 return bless $self, $class;
81}
82
83sub process
84{
85 my $self = shift (@_);
86 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
87
88 my ($filename_full_path, $filename_no_path) = $self->get_full_filenames($base_dir, $file);
89 # do something about OIDtype so no hashing
90
91 # old code was in effect the following.
92 if ($doc_obj->{'OIDtype'} =~ /^hash$/) {
93 $doc_obj->set_OIDtype ("incremental");
94 }
95
96 my $top_section = $doc_obj->get_top_section();
97 # Extract metadata
98 my $ogg = Ogg::Vorbis::Header::PurePerl->new($filename_full_path);
99
100 # Comments added to the file
101 foreach my $key ($ogg->comment_tags())
102 {
103 # Convert key to title case
104 my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
105 foreach my $value ($ogg->comment($key))
106 {
107 if (defined $value && $value ne "") {
108 $doc_obj->add_metadata($top_section, $keytc, $value);
109 }
110 }
111 }
112
113 # Technical data (optional)
114 if ($self->{'add_technical_metadata'}) {
115 foreach my $key (keys %{$ogg->info})
116 {
117 # Convert key to title case
118 my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
119 my $value = $ogg->info->{$key};
120 if (defined $value && $value ne "") {
121 $doc_obj->add_metadata($top_section, $keytc, $value);
122 }
123 }
124 }
125
126 $doc_obj->add_metadata ($top_section, "FileFormat", "OggVorbis");
127 $doc_obj->add_metadata ($top_section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Source]\">");
128 $doc_obj->add_metadata ($top_section, "/srclink", "</a>");
129 # srcicon (need to include "iogg.gif" in the greenstone images directory
130 $doc_obj->add_metadata ($top_section, "srcicon", "<img src=\"_httpprefix_/images/iogg.gif\" title=\"Download\" border=0>");
131
132 # add NoText metadata which can be used to suppress the dummy text
133 $doc_obj->add_metadata ($top_section, "NoText", "1");
134
135 # Add the actual file as an associated file
136 $doc_obj->associate_file($filename_full_path, $filename_no_path, "VORBIS", $top_section);
137
138}
139
140
1411;
Note: See TracBrowser for help on using the repository browser.