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

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

Committing Arnaud Yvan's MediainfoOGVPlugin.pm for the next release of Greenstone2.

File size: 7.9 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`;
147 print $outhandle "$video_metadata\n" if ($verbosity > 2);
148
149 # There are 10 fields separated by |, split these into ordered, individual-named variables
150 my ($formattedduration,$duration,$mfilesize,$artist,$title,$date,$location,$organization,$copyright,$contact) = split(/\|/,$video_metadata);
151 $duration = int($duration/1000);
152 $artist =~ s/\\047/\'/g; # Perl's way of doing: $artist = `echo $artist | sed \"s/\\047/'/g\"`;
153 $title =~ s/\\047/\'/g; # $title = `echo $title | sed \"s/\\047/'/g\"`;
154
155 #print STDERR "**** RESULT = $formattedduration\n$duration\n$mfilesize\n$artist\n$title\n$date\n$location\n$organization\n$copyright\n$contact\n";
156 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);
157
158
159 # Add the file as an associated file ...
160 my $section = $doc_obj->get_top_section();
161 my $file_format = $self->{'file_format'} || "ogv";
162 my $mime_type = $self->{'mime_type'} || "video/ogg";
163 my $assoc_field = $self->{'assoc_field'} || "movie";
164
165 # The assocfilename is the url-encoded version of the utf8 filename
166 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
167
168 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section);
169 $doc_obj->add_metadata ($section, "FileFormat", $file_format);
170 $doc_obj->add_metadata ($section, "dc.Format", $file_format);
171 $doc_obj->add_metadata ($section, "MimeType", $mime_type);
172 $doc_obj->add_utf8_metadata ($section, $assoc_field, $doc_obj->get_source()); # Source metadata is already in utf8
173
174 $doc_obj->add_metadata ($section, "FormattedDuration", $formattedduration);
175 $doc_obj->add_metadata ($section, "Duration", $duration);
176
177 $doc_obj->add_metadata ($section, "srclink",
178 "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
179 $doc_obj->add_metadata ($section, "srcicon", "_".$self->{'srcicon'}."_");
180 $doc_obj->add_metadata ($section, "/srclink", "</a>");
181
182 $doc_obj->add_metadata($section,"mFileSize",$mfilesize);
183 $doc_obj->add_utf8_metadata($section,"dc.Creator",$artist);
184 $doc_obj->add_utf8_metadata($section,"Artist",$artist);
185 $doc_obj->add_utf8_metadata($section,"dc.Title",$title);
186 $doc_obj->add_utf8_metadata($section,"Title",$title);
187 $doc_obj->add_utf8_metadata($section,"dc.Date",$date);
188 $doc_obj->add_utf8_metadata($section,"Date",$date);
189 $doc_obj->add_utf8_metadata($section,"Location",$location);
190 $doc_obj->add_utf8_metadata($section,"dc.Publisher",$organization);
191 $doc_obj->add_utf8_metadata($section,"Organization",$organization);
192 $doc_obj->add_utf8_metadata($section,"Copyright",$copyright);
193 $doc_obj->add_utf8_metadata($section,"Contact",$contact);
194
195 # we have no text - add dummy text and NoText metadata
196 $self->add_dummy_text($doc_obj, $section);
197
198# print STDERR "\n\n**** END of MediainfoOGVPlugin\n\n";
199
200 return 1;
201}
202
203
2041;
205
206
207
208
209
210
211
212
213
214
215
Note: See TracBrowser for help on using the repository browser.