Ignore:
Timestamp:
2008-06-05T09:29:32+12:00 (16 years ago)
Author:
kjdon
Message:

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/plugins/MP3Plugin.pm

    r15865 r15872  
    11###########################################################################
    22#
    3 # MP3Plug.pm -- Plugin for MP3 files (MPEG audio layer 3).
     3# MP3Plugin.pm -- Plugin for MP3 files (MPEG audio layer 3).
    44#
    55# A component of the Greenstone digital library software from the New
     
    2626
    2727
    28 package MP3Plug;
    29 
    30 use UnknownPlug;
     28package MP3Plugin;
     29
     30use BasePlugin;
    3131
    3232use strict;
    3333no strict 'refs'; # allow filehandles to be variables and viceversa
     34no strict 'subs';
    3435
    3536use MP3::Info;
     
    3839
    3940sub BEGIN {
    40     @MP3Plug::ISA = ('UnknownPlug');
     41    @MP3Plugin::ISA = ('BasePlugin');
    4142}
    4243
    4344my $arguments =
    4445    [ { 'name' => "process_exp",
    45     'desc' => "{BasPlug.process_exp}",
     46    'desc' => "{BasePlugin.process_exp}",
    4647    'type' => "regexp",
    4748    'deft' => &get_default_process_exp(),
    4849    'reqd' => "no" },
    4950      { 'name' => "assoc_images",
    50         'desc' => "{MP3Plug.assoc_images}",
     51        'desc' => "{MP3Plugin.assoc_images}",
    5152        'type' => "flag",
    5253        'deft' => "",
    5354        'reqd' => "no" },
    5455      { 'name' => "applet_metadata",
    55     'desc' => "{MP3Plug.applet_metadata}",
     56    'desc' => "{MP3Plugin.applet_metadata}",
    5657    'type' => "flag",
    5758    'deft' => "" },
    5859      { 'name' => "metadata_fields",
    59     'desc' => "{MP3Plug.metadata_fields}",
     60    'desc' => "{MP3Plugin.metadata_fields}",
    6061    'type' => "string",
    6162    'deft' => "Title,Artist,Genre" } ];
    6263
    63 my $options = { 'name'     => "MP3Plug",
    64         'desc'     => "{MP3Plug.desc}",
     64my $options = { 'name'     => "MP3Plugin",
     65        'desc'     => "{MP3Plugin.desc}",
    6566        'abstract' => "no",
    6667        'inherits' => "yes",
     
    7273    push(@$pluginlist, $class);
    7374
    74     if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
    75     if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
    76 
    77     my $self = new UnknownPlug($pluginlist, $inputargs, $hashArgOptLists);
     75    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
     76    push(@{$hashArgOptLists->{"OptList"}},$options);
     77
     78    my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
    7879
    7980    return bless $self, $class;
     
    8283sub get_default_process_exp {
    8384    return q^(?i)\.mp3$^;
     85}
     86
     87sub process {
     88    my $self = shift (@_);
     89    my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
     90
     91    my ($filename_full_path, $filename_no_path) = $self->get_full_filenames($base_dir, $file);
     92    # do something about OIDtype so no hashing
     93     
     94    # old code was in effect the following.
     95    if ($doc_obj->{'OIDtype'} =~ /^hash$/) {
     96    $doc_obj->set_OIDtype ("incremental");
     97    }
     98
     99
     100    # associate the file with the document
     101    if ($self->associate_mp3_file($filename_full_path, $filename_no_path, $doc_obj) != 1)
     102    {
     103    print "MP3Plugin: couldn't process \"$filename_full_path\"\n";
     104    return 0;
     105    }
     106   
     107    #whats this crap?
     108   my $text = &gsprintf::lookup_string("{BasePlugin.dummy_text}",1);
     109    if ($self->{'assoc_images'}) {
     110    $text .= "[img1]<br>";
     111    $text .= "[img2]<br>";
     112    }
     113    $doc_obj->add_utf8_text($doc_obj->get_top_section(), $text);
     114
    84115}
    85116
     
    155186
    156187    $doc_obj->associate_file($filename, $dst_file, $mime_type, $section);
    157     $doc_obj->add_metadata ($section, "Source", $file);
    158188    $doc_obj->add_metadata ($section, $assoc_field, $assoc_name);
    159189    $doc_obj->add_metadata ($section, "srcurl", $assoc_url);
     
    295325
    296326
    297 
    298 # The MP3Plug read() function is based on UnknownPlug read().  This
    299 # function does all the right things to make general options work for
    300 # a given plugin.
    301 
    302 my $mp3_doc_count = 0; ## is this used anywhere now !!???
    303 
    304 sub read {
    305     my $self = shift (@_);
    306     my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
    307 
    308     my $outhandle = $self->{'outhandle'};
    309 
    310     #check for associate_ext, blocking etc
    311     my ($block_status,$filename) = $self->read_block(@_);   
    312     return $block_status if ((!defined $block_status) || ($block_status==0));
    313 
    314     print STDERR "<Processing n='$file' p='MP3Plug'>\n" if ($gli);
    315     print $outhandle "MP3Plug processing \"$filename\"\n"
    316         if $self->{'verbosity'} > 1;
    317 
    318     #if there's a leading directory name, eat it...
    319     $file =~ s/^.*[\/\\]//;
    320    
    321     # create a new document
    322     my $doc_obj = new doc ($filename, "indexed_doc");
    323     $mp3_doc_count++;
    324    
    325 ##    $doc_obj->set_OIDtype ($processor->{'OIDtype'}); 
    326     if ($processor->{'OIDtype'} =~ /^(assigned|dirname)$/) {
    327     $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});
    328     }
    329     else {
    330     $doc_obj->set_OIDtype ("incremental");    # this is done to avoid hashing content of file
    331     }
    332     $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "Plugin", "$self->{'plugin_type'}");
    333     $doc_obj->add_utf8_metadata($doc_obj->get_top_section(), "FileSize", (-s $filename));
    334 
    335     # associate the file with the document
    336     if (associate_mp3_file($self, $filename, $file, $doc_obj) != 1)
    337     {
    338     print "MP3Plug: couldn't process \"$filename\"\n";
    339     return 0;
    340     }
    341 
    342     #create an empty text string so we don't break downstream plugins
    343     my $text = &gsprintf::lookup_string("{BasPlug.dummy_text}",1);
    344     if ($self->{'assoc_images'}) {
    345     $text .= "[img1]<br>";
    346     $text .= "[img2]<br>";
    347     }
    348     # include any metadata passed in from previous plugins
    349     my $section = $doc_obj->get_top_section();
    350     $self->extra_metadata ($doc_obj, $section, $metadata);
    351 
    352     $self->title_fallback($doc_obj,$section,$file);
    353 
    354     # do plugin specific processing of doc_obj
    355     return undef unless defined ($self->process (\$text, $pluginfo, $base_dir,
    356                          $file, $metadata, $doc_obj));
    357 
    358     # do any automatic metadata extraction
    359     $self->auto_extract_metadata ($doc_obj);
    360 
    361     # add an OID
    362     $doc_obj->set_OID();
    363     $doc_obj->add_utf8_text($section, $text);
    364 
    365     # process the document
    366     $processor->process($doc_obj);
    367 
    368     $self->{'num_processed'} ++;
    369     return 1;
    370 }
    371 
    372 
     327# we want to use mp3:Title if its there, otherwise we'll use BasePlugin method
    373328sub title_fallback
    374329{
     
    382337    }
    383338    else {
    384         &BasPlug::title_fallback($self, $doc_obj, $section, $file);
     339        $self->BasePlugin::title_fallback($doc_obj, $section, $file);
    385340    }
    386341    }
Note: See TracChangeset for help on using the changeset viewer.