[10395] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
[15872] | 3 | # RealMediaPlugin.pm -- Extract metadata from Real Media files
|
---|
[10395] | 4 | #
|
---|
| 5 | # Original code by Xin Gao
|
---|
| 6 | #
|
---|
| 7 | # A component of the Greenstone digital library software
|
---|
| 8 | # from the New Zealand Digital Library Project at the
|
---|
| 9 | # University of Waikato, New Zealand.
|
---|
| 10 | #
|
---|
| 11 | # Copyright (C) 2005 New Zealand Digital Library Project
|
---|
| 12 | #
|
---|
| 13 | # This program is free software; you can redistribute it and/or modify
|
---|
| 14 | # it under the terms of the GNU General Public License as published by
|
---|
| 15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | # (at your option) any later version.
|
---|
| 17 | #
|
---|
| 18 | # This program is distributed in the hope that it will be useful,
|
---|
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 21 | # GNU General Public License for more details.
|
---|
| 22 | #
|
---|
| 23 | # You should have received a copy of the GNU General Public License
|
---|
| 24 | # along with this program; if not, write to the Free Software
|
---|
| 25 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 26 | #
|
---|
| 27 | ###########################################################################
|
---|
| 28 |
|
---|
[15872] | 29 | package RealMediaPlugin;
|
---|
[10395] | 30 |
|
---|
| 31 |
|
---|
[15872] | 32 | use BasePlugin;
|
---|
[10395] | 33 | use rm::Header::PurePerl;
|
---|
| 34 |
|
---|
| 35 | use strict;
|
---|
| 36 | no strict 'refs'; # make an exception so we can use variables as filehandles
|
---|
[15872] | 37 | no strict 'subs';
|
---|
[10395] | 38 |
|
---|
| 39 | sub BEGIN {
|
---|
[15872] | 40 | @RealMediaPlugin::ISA = ('BasePlugin');
|
---|
[10395] | 41 | }
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | my $arguments =
|
---|
| 45 | [ { 'name' => "process_exp",
|
---|
[15872] | 46 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[10395] | 47 | 'type' => "regexp",
|
---|
| 48 | 'deft' => &get_default_process_exp(),
|
---|
| 49 | 'reqd' => "no" } ];
|
---|
| 50 |
|
---|
[15872] | 51 | my $options = { 'name' => "RealMediaPlugin",
|
---|
| 52 | 'desc' => "{RealMediaPlugin.desc}",
|
---|
[10395] | 53 | 'abstract' => "no",
|
---|
| 54 | 'inherits' => "yes",
|
---|
| 55 | 'args' => $arguments };
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 | # This plugin processes Real Media files with the suffixes ".rm" and ".rmvb"
|
---|
| 59 | sub get_default_process_exp
|
---|
| 60 | {
|
---|
| 61 | return q^(?i)(\.rm|rmvb)$^;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 |
|
---|
| 65 | sub new
|
---|
| 66 | {
|
---|
| 67 | my ($class) = shift(@_);
|
---|
| 68 | my ($pluginlist, $inputargs, $hashArgOptLists) = @_;
|
---|
| 69 | push(@$pluginlist, $class);
|
---|
| 70 |
|
---|
[15872] | 71 | push(@{$hashArgOptLists->{"ArgList"}}, @{$arguments});
|
---|
| 72 | push(@{$hashArgOptLists->{"OptList"}}, $options);
|
---|
[10395] | 73 |
|
---|
[15872] | 74 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10395] | 75 |
|
---|
| 76 | return bless $self, $class;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[17026] | 79 | # we don't want to hash on the file
|
---|
| 80 | sub get_oid_hash_type {
|
---|
| 81 | my $self = shift (@_);
|
---|
| 82 | return "hash_on_ga_xml";
|
---|
| 83 | }
|
---|
| 84 |
|
---|
[15872] | 85 | sub process
|
---|
[10395] | 86 | {
|
---|
| 87 | my $self = shift (@_);
|
---|
[15872] | 88 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[10395] | 89 |
|
---|
[16392] | 90 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
[15872] | 91 | my $top_section = $doc_obj->get_top_section();
|
---|
[10395] | 92 |
|
---|
| 93 | my $text = "";
|
---|
[15872] | 94 | my $real_media = rm::Header::PurePerl->new($filename_full_path);
|
---|
[16994] | 95 | if (!defined $real_media || !defined $real_media->info) {
|
---|
| 96 | my $outhandle = $self->{'outhandle'};
|
---|
| 97 | print $outhandle "RealMediaPlugin: $filename_no_path is not a real media file\n";
|
---|
| 98 | return undef;
|
---|
| 99 | }
|
---|
[10395] | 100 | foreach my $key (keys %{$real_media->info})
|
---|
| 101 | {
|
---|
| 102 | my $value = $real_media->info->{$key};
|
---|
| 103 | $doc_obj->add_metadata($top_section, $key, $value);
|
---|
| 104 | $text .= "$key: $value\n";
|
---|
| 105 | }
|
---|
[16994] | 106 |
|
---|
[10395] | 107 | $doc_obj->add_utf8_text($top_section, "<pre>\n$text\n</pre>");
|
---|
[15872] | 108 | $doc_obj->add_metadata($top_section, "FileFormat", "RealMedia");
|
---|
[10395] | 109 |
|
---|
[21760] | 110 | #$doc_obj->add_metadata($top_section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
|
---|
| 111 | #$doc_obj->add_metadata($top_section, "/srclink", "</a>");
|
---|
| 112 | $doc_obj->add_metadata ($top_section, "srclink_file", "[SourceFile]");
|
---|
[21746] | 113 | $doc_obj->add_metadata($top_section, "srcicon", "_iconrmvideo_");
|
---|
[10395] | 114 |
|
---|
[16956] | 115 | # Add the actual filename as it exists on the file system (URL-encoded) as an
|
---|
| 116 | # associated file by making sure we undo any escaped URL-encoding there may be
|
---|
| 117 | my $assoc_file = $doc_obj->get_assocfile_from_sourcefile(); # just url-encoded filename, no path
|
---|
| 118 | $doc_obj->associate_file($filename_full_path, $assoc_file, "RealMedia", $top_section);
|
---|
[10395] | 119 |
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | 1;
|
---|