Index: extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm
===================================================================
--- extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm	(revision 18429)
+++ extensions/gsdl-video/trunk/perllib/plugins/VideoPlugin.pm	(revision 18476)
@@ -1,5 +1,5 @@
-########################################################################
+######################################################################
 #
-# VideoPlug.pm -- plugin for processing video largely based on ImagePlug
+# VideoPlugin.pm -- plugin for processing video largely based on ImagePlug
 # A component of the Greenstone digital library software
 # from the New Zealand Digital Library Project at the 
@@ -28,4 +28,5 @@
 use strict;
 no strict 'refs'; # allow filehandles to be variables and viceversa
+no strict 'subs';
 
 use videoconvert;
@@ -43,4 +44,21 @@
 
 }
+
+
+# Customized from BasePlugin. Make 'incremental' the default 
+# to avoid Greenstone hashing on the file (which in the case of video
+# is HUGE) to generate OID. Also supress 'hash' as option so the user
+# can't choose it.
+
+our $oidtype_list = 
+    [ { 'name' => "auto",
+	'desc' => "{BasePlugin.OIDtype.auto}" },
+      { 'name' => "assigned",
+        'desc' => "{import.OIDtype.assigned}" },
+      { 'name' => "incremental",
+        'desc' => "{import.OIDtype.incremental}" },
+      { 'name' => "dirname",
+        'desc' => "{import.OIDtype.dirname}" } ];
+
 
 my $arguments =
@@ -50,4 +68,12 @@
 	'deft' => &get_default_process_exp(),
 	'reqd' => "no" },
+      { 'name' => "OIDtype",
+	'desc' => "{import.OIDtype}",
+	'type' => "enum",
+	'list' => $oidtype_list,
+	'deft' => "incremental",
+	'reqd' => "no",
+	'modegli' => "2" },
+
       { 'name' => "noscaleup",
 	'desc' => "{VideoPlug.noscaleup}",
@@ -138,5 +164,5 @@
 	'reqd' => "no" } ];
 
-my $options = { 'name'     => "VideoPlug",
+my $options = { 'name'     => "VideoPlugin",
 		'desc'     => "{VideoPlug.desc}",
 		'abstract' => "no",
@@ -168,8 +194,13 @@
 	my $result = `ffmpeg -h 2>&1`;
 
+
 	if (!defined $result || $result !~ m/^FFmpeg version/) {
-	    $self->{'ffmpeg_not_installed'} = 1;
+	    $self->{'ffmpeg_installed'} = 0;
 	    print STDERR $result;
 	}
+	else {
+	    $self->{'ffmpeg_installed'} = 1;
+	}
+
     }
 
@@ -212,5 +243,5 @@
     my $self = shift (@_);
 
-    return q^\.(?i)(mpe?g|flv|qt|vob|avi)$^; 
+    return q^(?i)\.(mpe?g|flv|mov|qt|wmv|vob|avi|mp4|m4v)$^; 
 }
 
@@ -247,5 +278,5 @@
     my $minimumsize = $self->{'minimumsize'};
     if (defined $minimumsize && (-s $filename < $minimumsize)) {
-        print $outhandle "VideoPlug: \"$filename\" too small, skipping\n"
+        print $outhandle "VideoPlugin: \"$filename\" too small, skipping\n"
 	    if ($verbosity > 1);
     }
@@ -559,4 +590,5 @@
     }
 
+
     if ($self->{'extractkeyframes'}) {
 
@@ -584,6 +616,4 @@
     }
 
-
-    
     # Make a screen-sized version of the picture if requested
     if ($self->{'extractscreenview'}) {
@@ -626,5 +656,5 @@
 	    $doc_obj->add_utf8_metadata ($section, "screenicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Screen]\" width=[ScreenWidth] height=[ScreenHeight]>");
 	} else {
-	    print $outhandle "VideoPlug: couldn't find \"$screenviewfilename\"\n";
+	    print $outhandle "VideoPlugin: couldn't find \"$screenviewfilename\"\n";
 	}
     }
@@ -636,106 +666,58 @@
 
 
-
-# The VideoPlug read() function. 
-# VideoPlug overrides read() because there is no need to read the actual 
-# text of the file in, because the contents of the file is not text...
-#
-# Return number of files processed, undef if can't process
-# Note that $base_dir might be "" and that $file might 
-# include directories
-
-sub read {
-    my $self = shift (@_);
-    my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
+sub read_into_doc_obj {
+    my $self = shift (@_);  
+    my ($pluginfo, $base_dir, $file, $block_hash, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
 
     my $outhandle = $self->{'outhandle'};
 
-    #check process and block exps, smart block, etc
-    my ($block_status,$filename) = $self->read_block(@_);    
-    return $block_status if ((!defined $block_status) || ($block_status==0));
-
-    print STDERR "<Processing n='$file' p='VideoPlug'>\n" if ($gli);
-    print $outhandle "VideoPlug processing $file\n"
+    # should we move this to read? What about secondary plugins?
+    print STDERR "<Processing n='$file' p='$self->{'plugin_type'}'>\n" if ($gli);
+    print $outhandle "$self->{'plugin_type'} processing $file\n"
 	    if $self->{'verbosity'} > 1;
 
-    # None of this works very well on Windows 95/98...
-    if ($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT()) {
-	if ($gli) {
-	    print STDERR "<ProcessingError n='$file' r='Windows 95/98 not supported'>\n";
-	}
-	print $outhandle "VideoPlug: Windows 95/98 not supported\n";
-	return -1;
-    }
-
-    # None of this is going to work very well without ffmpeg
-    if ($self->{'ffmpeg_not_installed'}) {
-	if ($gli) {
-	    print STDERR "<ProcessingError n='$file' r='ffmpeg not installed'>\n";
-	}
-	print $outhandle "VideoPlug: ffmpeg not installed\n";
-	return -1;
-    }
-
-    #if there's a leading directory name, eat it...
-    $file =~ s/^.*[\/\\]//;
+    my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
+
+    # create a new document
+    my $doc_obj = new doc ($filename_full_path, "indexed_doc", $self->{'file_rename_method'});
+
+
+    my $top_section = $doc_obj->get_top_section();
+
+    ### <Video Specific> ###
+    $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});    
+    ### </Video Specific> ###
+
+
+    $doc_obj->add_utf8_metadata($top_section, "Plugin", "$self->{'plugin_type'}");
+    $doc_obj->add_utf8_metadata($top_section, "FileSize", (-s $filename_full_path));
+ 
+    # sets the UTF8 filename (Source) for display and sets the url ref to URL encoded version
+    # of the UTF8 filename (SourceFile) for generated files
+    $self->set_Source_metadata($doc_obj, $filename_no_path);
+
+
+    # plugin specific stuff - what args do we need here??
+    unless (defined ($self->process($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli))) {
+	print STDERR "<ProcessingError n='$file'>\n" if ($gli);
+	return (-1,undef);
+    }
     
-    # create a new document
-    my $doc_obj = new doc ($filename, "indexed_doc");
-
-    $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});    
-    $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
-
-    #run convert to get the thumbnail and extract size and type info
-    my $result = $self->run_convert($base_dir, $filename, $file, $doc_obj);
-    
-    if (!defined $result)
-    {
-	if ($gli) {
-	    print STDERR "<ProcessingError n='$file'>\n";
-	}
-	print $outhandle "VideoPlug: couldn't process \"$filename\"\n";
-	return -1; # error during processing
-    }
-
-    #create an empty text string so we don't break downstream plugins 
-    my $text = &gsprintf::lookup_string("{BasePlugin.dummy_text}");
     # include any metadata passed in from previous plugins 
     # note that this metadata is associated with the top level section
     my $section = $doc_obj->get_top_section();
+    # can we merge these two methods??
+    $self->add_associated_files($doc_obj, $filename_full_path);
     $self->extra_metadata ($doc_obj, $section, $metadata);
-
-    # do plugin specific processing of doc_obj
-    unless (defined ($self->process(\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj))) {
-	print STDERR "<ProcessingError n='$file'>\n" if ($gli);
-	return -1;
-    }
-
-
-
-    # do any automatic metadata extraction
-    $self->auto_extract_metadata ($doc_obj);
+    $self->auto_extract_metadata($doc_obj);
 
     # if we haven't found any Title so far, assign one
     # this was shifted to here from inside read()
-    $self->title_fallback($doc_obj,$section,$file);
-
-    # add an OID 
-    # 
-    # Caveat: Don't want to hash on the source/converted video as typically
-    # prohibitively large => temporarily set source/converted filename 
-    # to 'undef' (causes set_OID to hash on metadata and text stored within
-    # $doc_ob) then restore to previous value.
-    #
-    my $stored_gsdlsourcefilename = $doc_obj->get_source_filename();
-    $doc_obj->set_source_filename(undef);
-
+    $self->title_fallback($doc_obj,$section,$filename_no_path);
+    
     $self->add_OID($doc_obj);
 
-    $doc_obj->set_source_filename($stored_gsdlsourcefilename);
-
-    $doc_obj->add_text($section, $text);
-
-    # process the document
-    $processor->process($doc_obj);
+
+    ### <Video Specific> ###
 
     if (($self->{'enablestreaming'}) && ($self->{'extractkeyframes'})) {
@@ -753,19 +735,72 @@
 	$videoconvert->run_general_cmd($streamkeyframes_cmd,$streamkeyframes_options);
     }
-
-
-    $self->{'num_processed'}++;
-
-    return 1;
-}
+    ### </Video Specific> ###
+    
+    return (1,$doc_obj);
+}
+
+sub add_dummy_text {
+    my $self = shift(@_);
+    my ($doc_obj, $section) = @_;
+
+    # add NoText metadata so we can hide this dummy text in format statements
+    $doc_obj->add_metadata($section, "NoText", "1");
+    $doc_obj->add_text($section, &gsprintf::lookup_string("{BasePlugin.dummy_text}",1));
+    
+}
+
+
+
 
 # do plugin specific processing of doc_obj
 sub process {
     my $self = shift (@_);
-    my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj) = @_;
+    # options??
+    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
+
     my $outhandle = $self->{'outhandle'};
-    
+
+    my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
+
+
+    if ($self->{'ffmpeg_installed'}) {
+	my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
+	my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
+
+
+	#run convert to get the thumbnail and extract size and type info
+	my $result = $self->run_convert($base_dir, $filename_full_path, 
+					$url_encoded_filename, $doc_obj);
+	
+	if (!defined $result) {
+	    if ($gli) {
+		print STDERR "<ProcessingError n='$file'>\n";
+	    }
+	    print $outhandle "VideoPlugin: couldn't process \"$filename_full_path\"\n";
+	    return (-1,undef); # error during processing
+	}
+    } 
+    else {
+	if ($gli) {
+	    &gsprintf(STDERR, "<Warning p='VideoPlugin' r='{VideoConverter.noconversionavailable}: {VideoConverter.".$self->{'no_image_conversion_reason'}."}'>");
+	}
+	# all we do is add the original video file as an associated file, and set up srclink etc
+	my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
+	my $section = $doc_obj->get_top_section();
+
+	$doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
+
+	$doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
+	$doc_obj->add_metadata ($section, "/srclink", "</a>");
+	$doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\" width=\"100\">");
+
+    }
+    #we have no text - adds dummy text and NoText metadata
+    $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
+
     return 1;
-}
+
+}
+
 
 
