source: main/trunk/greenstone2/perllib/plugins/MediainfoOGVPlugin.pm@ 22363

Last change on this file since 22363 was 22363, checked in by ak19, 14 years ago

Adding in the adjustments to the mediainfoogv plugin that were mailed to Arnaud Ivan

File size: 8.5 KB
Line 
1###########################################################################
2#
3# MediainfoOGVPlugin.pm -- Plugin for OGV multimedia files
4#
5# A component of the Greenstone digital library software from the New
6# Zealand Digital Library Project at the University of Waikato, New
7# Zealand.
8#
9# Copyright (C) 2001 Gordon W. Paynter
10# Copyright (C) 2001 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful, but
18# WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20# General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28# MediainfoOGVPlugin - a plugin for OGV multimedia files
29
30# This is a simple Plugin for importing OGV multimedia files.
31# Mediainfo will retrieve the metadata of the file. A fictional document will
32# be created for every such file, and the file itself will be passed
33# to Greenstone as the "associated file" of the document.
34
35# Here's an example where it is useful: I have a collection of
36# ogg movie files with names like conference_20080402.ogv.
37# I add this line to the collection configuration file:
38
39# plugin MediainfoOGVPlugin -process_exp "*.ogv" -assoc_field "movie"
40
41# A document is created for each movie, with the associated movie
42# file's name in the "movie" metadata field.
43
44# Te plugin also add some metadata :
45# Duration (in seconds), filesize, title, artist, location, organization,
46# date, contact, copyright.
47
48
49
50package MediainfoOGVPlugin;
51
52use BasePlugin;
53
54use strict;
55no strict 'refs'; # allow filehandles to be variables and viceversa
56no strict 'subs';
57
58sub BEGIN {
59 @MediainfoOGVPlugin::ISA = ('BasePlugin');
60}
61
62my $arguments = [ { 'name' => "assoc_field",
63 'desc' => "{MediainfoOGVPlugin.assoc_field}",
64 'type' => "string",
65 'deft' => "movie",
66 'reqd' => "no" },
67 { 'name' => "file_format",
68 'desc' => "{MediainfoOGVPlugin.file_format}",
69 'type' => "string",
70 'deft' => "ogv",
71 'reqd' => "no" },
72 { 'name' => "mime_type",
73 'desc' => "{MediainfoOGVPlugin.mime_type}",
74 'type' => "string",
75 'deft' => "video/ogg",
76 'reqd' => "no" },
77 { 'name' => "srcicon",
78 'desc' => "{MediainfoOGVPlugin.srcicon}",
79 'type' => "string",
80 'deft' => "iconogg",
81 'reqd' => "no" },
82 { 'name' => "process_extension",
83 'desc' => "{MediainfoOGVPlugin.process_extension}",
84 'type' => "string",
85 'deft' => "ogv",
86 'reqd' => "no" } ];
87
88my $options = { 'name' => "MediainfoOGVPlugin",
89 'desc' => "{MediainfoOGVPlugin.desc}",
90 'abstract' => "no",
91 'inherits' => "yes",
92 'args' => $arguments };
93
94
95sub new {
96 my ($class) = shift (@_);
97 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
98 push(@$pluginlist, $class);
99
100 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
101 push(@{$hashArgOptLists->{"OptList"}},$options);
102
103 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
104
105 # "-process_extension" is a simpler alternative to -process_exp for non-regexp people
106 if (!$self->{'process_exp'} && $self->{'process_extension'}) {
107 $self->{'process_exp'} = "\\." . $self->{'process_extension'} . "\$";
108 }
109
110 # Check that Mediainfo is installed and available on the path (except for Windows 95/98)
111 if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
112 my $result = `mediainfo 2>&1`;
113 if ($? == -1 || $? == 256) { # Linux and Windows return different values for "program not found"
114 $self->{'mediainfo_not_installed'} = 1;
115 }
116 }
117
118 return bless $self, $class;
119}
120
121
122# MediainfoOGVPlugin processing of doc_obj.
123
124sub process {
125 my $self = shift (@_);
126 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
127
128 #print STDERR "\n\n**** START of processing MediainfoOGVPlugin\n\n";
129
130 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
131 my $outhandle = $self->{'outhandle'};
132 my $verbosity = $self->{'verbosity'};
133
134 # check the filename is okay - do we need this??
135 if ($filename_full_path eq "" || $filename_no_path eq "") {
136 print $outhandle "UnknownPlugin: couldn't process \"$filename_no_path\"\n";
137 return undef;
138 }
139
140 # Retrieve the file metadata
141
142 my $command = "mediainfo --inform=\"General;%Duration/String2%|%Duration%|%FileSize/String2%|%Performer%|%Title%|%Recorded_Date%|%Recorded/Location%|%Producer%|%Copyright%|%Publisher%\" \"$filename_full_path\"";
143 print $outhandle "$command\n" if ($verbosity > 2);
144
145 # execute the mediainfo command and store the output of execution in $videodata
146 # my $video_metadata = `$command`; # backticks operator way
147 # Another way to execute the command: better experience with this than
148with backticks operator above:
149 # use open() to read the output of executing the command (which is
150piped through to a handle using the | operator)
151 my $video_metadata;
152 if (open(VMIN,"$command|")) {
153 my $line;
154
155 # we read a line of output at a time
156 while (defined ($line=<VMIN>)) {
157 #print STDERR "***** line = $line\n";
158
159 $video_metadata .= $line;
160 }
161
162 close(VMIN);
163 }
164
165 print $outhandle "$video_metadata\n" if ($verbosity > 2);
166
167 # There are 10 fields separated by |, split these into ordered, individual-named variables
168 my ($formattedduration,$duration,$mfilesize,$artist,$title,$date,$location,$organization,$copyright,$contact) = split(/\|/,$video_metadata);
169 $duration = int($duration/1000);
170 $artist =~ s/\\047/\'/g; # Perl's way of doing: $artist = `echo $artist | sed \"s/\\047/'/g\"`;
171 $title =~ s/\\047/\'/g; # $title = `echo $title | sed \"s/\\047/'/g\"`;
172
173 #print STDERR "**** RESULT = $formattedduration\n$duration\n$mfilesize\n$artist\n$title\n$date\n$location\n$organization\n$copyright\n$contact\n";
174 print $outhandle "RESULT = $formattedduration\n$duration\n$mfilesize\n$artist\n$title\n$date\n$location\n$organization\n$copyright\n$contact\n" if ($verbosity > 2);
175
176
177 # Add the file as an associated file ...
178 my $section = $doc_obj->get_top_section();
179 my $file_format = $self->{'file_format'} || "ogv";
180 my $mime_type = $self->{'mime_type'} || "video/ogg";
181 my $assoc_field = $self->{'assoc_field'} || "movie";
182
183 # The assocfilename is the url-encoded version of the utf8 filename
184 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
185
186 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section);
187 $doc_obj->add_metadata ($section, "FileFormat", $file_format);
188 $doc_obj->add_metadata ($section, "dc.Format", $file_format);
189 $doc_obj->add_metadata ($section, "MimeType", $mime_type);
190 $doc_obj->add_utf8_metadata ($section, $assoc_field, $doc_obj->get_source()); # Source metadata is already in utf8
191
192 $doc_obj->add_metadata ($section, "FormattedDuration", $formattedduration);
193 $doc_obj->add_metadata ($section, "Duration", $duration);
194
195 $doc_obj->add_metadata ($section, "srclink",
196 "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
197 $doc_obj->add_metadata ($section, "srcicon", "_".$self->{'srcicon'}."_");
198 $doc_obj->add_metadata ($section, "/srclink", "</a>");
199
200 $doc_obj->add_metadata($section,"mFileSize",$mfilesize);
201 $doc_obj->add_utf8_metadata($section,"dc.Creator",$artist);
202 $doc_obj->add_utf8_metadata($section,"Artist",$artist);
203 $doc_obj->add_utf8_metadata($section,"dc.Title",$title);
204 $doc_obj->add_utf8_metadata($section,"Title",$title);
205 $doc_obj->add_utf8_metadata($section,"dc.Date",$date);
206 $doc_obj->add_utf8_metadata($section,"Date",$date);
207 $doc_obj->add_utf8_metadata($section,"Location",$location);
208 $doc_obj->add_utf8_metadata($section,"dc.Publisher",$organization);
209 $doc_obj->add_utf8_metadata($section,"Organization",$organization);
210 $doc_obj->add_utf8_metadata($section,"Copyright",$copyright);
211 $doc_obj->add_utf8_metadata($section,"Contact",$contact);
212
213 # we have no text - add dummy text and NoText metadata
214 $self->add_dummy_text($doc_obj, $section);
215
216# print STDERR "\n\n**** END of MediainfoOGVPlugin\n\n";
217
218 return 1;
219}
220
221
2221;
223
224
225
226
227
228
229
230
231
232
233
Note: See TracBrowser for help on using the repository browser.