Changeset 22401


Ignore:
Timestamp:
2010-07-14T14:55:26+12:00 (14 years ago)
Author:
kjdon
Message:

tidied up a bit. Removed options that (I think) will always be set the same. and tidied the code a wee bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/MediainfoOGVPlugin.pm

    r22364 r22401  
    6060}
    6161
    62 my $arguments  =  [ { 'name' => "assoc_field",
     62my $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",
    6369    'desc' => "{MediainfoOGVPlugin.assoc_field}",
    6470    'type' => "string",
    65     'deft' => "movie",
     71    'deft' => "Movie",
    6672    '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      ];
    8774
    8875my $options = { 'name'     => "MediainfoOGVPlugin",
     
    10390    my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
    10491
    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
     95sub init {
     96    my $self = shift(@_);
     97    my ($verbosity, $outhandle, $failhandle) = @_;
     98
     99    $self->BasePlugin::init($verbosity, $outhandle, $failhandle);   
    109100
    110101    # Check that Mediainfo is installed and available on the path (except for Windows 95/98)
     
    116107    }
    117108
    118     return bless $self, $class;
    119 }
    120 
     109}
     110sub get_default_process_exp {
     111    return q^(?i)\.ogv$^;
     112}
    121113
    122114# MediainfoOGVPlugin processing of doc_obj.
     
    134126    # check the filename is okay - do we need this??
    135127    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";
    137129        return undef;
    138130    }
    139131
     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   
    140162    # Retrieve the file metadata
    141163    my $command = "mediainfo --inform=\"General;%Duration/String2%|%Duration%|%FileSize/String2%|%Performer%|%Title%|%Recorded_Date%|%Recorded/Location%|%Producer%|%Copyright%|%LICENSE%|%Publisher%\" \"$filename_full_path\"";
    142164    print $outhandle "$command\n" if ($verbosity > 2);
    143 
     165   
    144166    # execute the mediainfo command and store the output of execution in $videodata
    145167    # my $video_metadata = `$command`; # backticks operator way
     
    149171    if (open(VMIN,"$command|")) {
    150172        my $line;
    151 
     173   
    152174    # we read a line of output at a time
    153175        while (defined ($line=<VMIN>)) {
    154             #print STDERR "***** line = $line\n";
    155 
    156             $video_metadata .= $line;
     176        #print STDERR "***** line = $line\n";
     177       
     178        $video_metadata .= $line;
    157179        }
    158 
     180   
    159181        close(VMIN);
    160182    }
    161 
     183   
    162184    print $outhandle "$video_metadata\n" if ($verbosity > 2);
    163185
     
    170192    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);
    171193   
    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 filename
    179     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 utf8
    186194 
    187195    $doc_obj->add_metadata ($section, "FormattedDuration", $FormattedDuration);
    188196    $doc_obj->add_metadata ($section, "Duration", $Duration);
    189197 
    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>");
    194198
    195199    $doc_obj->add_metadata($section,"FileSize",$Filesize);
     
    211215    $doc_obj->add_utf8_metadata($section,"Contact",$Contact);
    212216 
    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";
    217219   
    218220    return 1;
Note: See TracChangeset for help on using the changeset viewer.