- Timestamp:
- 2010-07-14T14:55:26+12:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/plugins/MediainfoOGVPlugin.pm
r22364 r22401 60 60 } 61 61 62 my $arguments = [ { 'name' => "assoc_field", 62 my $arguments = 63 [ { 'name' => "process_exp", 64 'desc' => "{BasePlugin.process_exp}", 65 'type' => "regexp", 66 'deft' => &get_default_process_exp(), 67 'reqd' => "no" }, 68 { 'name' => "assoc_field", 63 69 'desc' => "{MediainfoOGVPlugin.assoc_field}", 64 70 'type' => "string", 65 'deft' => " movie",71 'deft' => "Movie", 66 72 '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" } ]; 73 ]; 87 74 88 75 my $options = { 'name' => "MediainfoOGVPlugin", … … 103 90 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists); 104 91 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 } 92 return bless $self, $class; 93 } 94 95 sub init { 96 my $self = shift(@_); 97 my ($verbosity, $outhandle, $failhandle) = @_; 98 99 $self->BasePlugin::init($verbosity, $outhandle, $failhandle); 109 100 110 101 # Check that Mediainfo is installed and available on the path (except for Windows 95/98) … … 116 107 } 117 108 118 return bless $self, $class; 119 } 120 109 } 110 sub get_default_process_exp { 111 return q^(?i)\.ogv$^; 112 } 121 113 122 114 # MediainfoOGVPlugin processing of doc_obj. … … 134 126 # check the filename is okay - do we need this?? 135 127 if ($filename_full_path eq "" || $filename_no_path eq "") { 136 print $outhandle " UnknownPlugin: couldn't process \"$filename_no_path\"\n";128 print $outhandle "MediainfoOGVPlugin: couldn't process \"$filename_no_path\"\n"; 137 129 return undef; 138 130 } 139 131 132 # Add the file as an associated file ... 133 my $section = $doc_obj->get_top_section(); 134 my $file_format = "ogv"; 135 my $mime_type = "video/ogg"; 136 my $assoc_field = $self->{'assoc_field'}; 137 138 # The assocfilename is the url-encoded version of the utf8 filename 139 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile(); 140 141 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section); 142 $doc_obj->add_metadata ($section, "FileFormat", $file_format); 143 $doc_obj->add_metadata ($section, "dc.Format", $file_format); 144 $doc_obj->add_metadata ($section, "MimeType", $mime_type); 145 $doc_obj->add_utf8_metadata ($section, $assoc_field, $doc_obj->get_source()); # Source metadata is already in utf8 146 147 $doc_obj->add_metadata ($section, "srclink", 148 "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">"); 149 $doc_obj->add_metadata ($section, "srcicon", "_iconogg_"); 150 $doc_obj->add_metadata ($section, "/srclink", "</a>"); 151 152 # we have no text - add dummy text and NoText metadata 153 $self->add_dummy_text($doc_obj, $section); 154 155 if (defined $self->{'mediainfo_not_installed'}) { 156 # can't do any extracted 157 print STDERR "Mediainfo not installed, so can't extract metadata\n"; 158 return 1; 159 } 160 161 140 162 # Retrieve the file metadata 141 163 my $command = "mediainfo --inform=\"General;%Duration/String2%|%Duration%|%FileSize/String2%|%Performer%|%Title%|%Recorded_Date%|%Recorded/Location%|%Producer%|%Copyright%|%LICENSE%|%Publisher%\" \"$filename_full_path\""; 142 164 print $outhandle "$command\n" if ($verbosity > 2); 143 165 144 166 # execute the mediainfo command and store the output of execution in $videodata 145 167 # my $video_metadata = `$command`; # backticks operator way … … 149 171 if (open(VMIN,"$command|")) { 150 172 my $line; 151 173 152 174 # we read a line of output at a time 153 175 while (defined ($line=<VMIN>)) { 154 155 156 176 #print STDERR "***** line = $line\n"; 177 178 $video_metadata .= $line; 157 179 } 158 180 159 181 close(VMIN); 160 182 } 161 183 162 184 print $outhandle "$video_metadata\n" if ($verbosity > 2); 163 185 … … 170 192 print $outhandle "RESULT = $FormattedDuration\n$Duration\n$Filesize\n$Artist\n$Title\n$Date\n$Location\n$Organization\n$Copyright\n$License\n$Contact\n" if ($verbosity > 2); 171 193 172 # Add the file as an associated file ...173 my $section = $doc_obj->get_top_section();174 my $file_format = $self->{'file_format'} || "ogv";175 my $mime_type = $self->{'mime_type'} || "video/ogg";176 my $assoc_field = $self->{'assoc_field'} || "movie";177 178 # The assocfilename is the url-encoded version of the utf8 filename179 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();180 181 $doc_obj->associate_file($filename_full_path, $assoc_file, $mime_type, $section);182 $doc_obj->add_metadata ($section, "FileFormat", $file_format);183 $doc_obj->add_metadata ($section, "dc.Format", $file_format);184 $doc_obj->add_metadata ($section, "MimeType", $mime_type);185 $doc_obj->add_utf8_metadata ($section, $assoc_field, $doc_obj->get_source()); # Source metadata is already in utf8186 194 187 195 $doc_obj->add_metadata ($section, "FormattedDuration", $FormattedDuration); 188 196 $doc_obj->add_metadata ($section, "Duration", $Duration); 189 197 190 $doc_obj->add_metadata ($section, "srclink",191 "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");192 $doc_obj->add_metadata ($section, "srcicon", "_".$self->{'srcicon'}."_");193 $doc_obj->add_metadata ($section, "/srclink", "</a>");194 198 195 199 $doc_obj->add_metadata($section,"FileSize",$Filesize); … … 211 215 $doc_obj->add_utf8_metadata($section,"Contact",$Contact); 212 216 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 #print STDERR "\n\n**** END of MediainfoOGVPlugin\n\n"; 217 219 218 220 return 1;
Note:
See TracChangeset
for help on using the changeset viewer.