Changeset 15872 for gsdl/trunk/perllib/plugins/MP3Plugin.pm
- Timestamp:
- 2008-06-05T09:29:32+12:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/plugins/MP3Plugin.pm
r15865 r15872 1 1 ########################################################################### 2 2 # 3 # MP3Plug .pm -- Plugin for MP3 files (MPEG audio layer 3).3 # MP3Plugin.pm -- Plugin for MP3 files (MPEG audio layer 3). 4 4 # 5 5 # A component of the Greenstone digital library software from the New … … 26 26 27 27 28 package MP3Plug ;29 30 use UnknownPlug;28 package MP3Plugin; 29 30 use BasePlugin; 31 31 32 32 use strict; 33 33 no strict 'refs'; # allow filehandles to be variables and viceversa 34 no strict 'subs'; 34 35 35 36 use MP3::Info; … … 38 39 39 40 sub BEGIN { 40 @MP3Plug ::ISA = ('UnknownPlug');41 @MP3Plugin::ISA = ('BasePlugin'); 41 42 } 42 43 43 44 my $arguments = 44 45 [ { 'name' => "process_exp", 45 'desc' => "{Bas Plug.process_exp}",46 'desc' => "{BasePlugin.process_exp}", 46 47 'type' => "regexp", 47 48 'deft' => &get_default_process_exp(), 48 49 'reqd' => "no" }, 49 50 { 'name' => "assoc_images", 50 'desc' => "{MP3Plug .assoc_images}",51 'desc' => "{MP3Plugin.assoc_images}", 51 52 'type' => "flag", 52 53 'deft' => "", 53 54 'reqd' => "no" }, 54 55 { 'name' => "applet_metadata", 55 'desc' => "{MP3Plug .applet_metadata}",56 'desc' => "{MP3Plugin.applet_metadata}", 56 57 'type' => "flag", 57 58 'deft' => "" }, 58 59 { 'name' => "metadata_fields", 59 'desc' => "{MP3Plug .metadata_fields}",60 'desc' => "{MP3Plugin.metadata_fields}", 60 61 'type' => "string", 61 62 'deft' => "Title,Artist,Genre" } ]; 62 63 63 my $options = { 'name' => "MP3Plug ",64 'desc' => "{MP3Plug .desc}",64 my $options = { 'name' => "MP3Plugin", 65 'desc' => "{MP3Plugin.desc}", 65 66 'abstract' => "no", 66 67 'inherits' => "yes", … … 72 73 push(@$pluginlist, $class); 73 74 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); 78 79 79 80 return bless $self, $class; … … 82 83 sub get_default_process_exp { 83 84 return q^(?i)\.mp3$^; 85 } 86 87 sub 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 84 115 } 85 116 … … 155 186 156 187 $doc_obj->associate_file($filename, $dst_file, $mime_type, $section); 157 $doc_obj->add_metadata ($section, "Source", $file);158 188 $doc_obj->add_metadata ($section, $assoc_field, $assoc_name); 159 189 $doc_obj->add_metadata ($section, "srcurl", $assoc_url); … … 295 325 296 326 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 373 328 sub title_fallback 374 329 { … … 382 337 } 383 338 else { 384 &BasPlug::title_fallback($self,$doc_obj, $section, $file);339 $self->BasePlugin::title_fallback($doc_obj, $section, $file); 385 340 } 386 341 }
Note:
See TracChangeset
for help on using the changeset viewer.