source: gsdl/trunk/perllib/plugins/RealMediaPlug.pm@ 14661

Last change on this file since 14661 was 13543, checked in by shaoqun, 17 years ago

fixed the bug that cause the server couldn't locate the file which is stored a subdirectory

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
Line 
1###########################################################################
2#
3# RealMediaPlug.pm -- Extract metadata from Real Media files
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
29package RealMediaPlug;
30
31
32use UnknownPlug;
33use rm::Header::PurePerl;
34
35use strict;
36no strict 'refs'; # make an exception so we can use variables as filehandles
37
38
39sub BEGIN {
40 @RealMediaPlug::ISA = ('UnknownPlug');
41}
42
43
44my $arguments =
45 [ { 'name' => "process_exp",
46 'desc' => "{BasPlug.process_exp}",
47 'type' => "regexp",
48 'deft' => &get_default_process_exp(),
49 'reqd' => "no" } ];
50
51my $options = { 'name' => "RealMediaPlug",
52 'desc' => "{RealMediaPlug.desc}",
53 'abstract' => "no",
54 'inherits' => "yes",
55 'args' => $arguments };
56
57
58# This plugin processes Real Media files with the suffixes ".rm" and ".rmvb"
59sub get_default_process_exp
60{
61 return q^(?i)(\.rm|rmvb)$^;
62}
63
64
65sub new
66{
67 my ($class) = shift(@_);
68 my ($pluginlist, $inputargs, $hashArgOptLists) = @_;
69 push(@$pluginlist, $class);
70
71 if (defined $arguments) { push(@{$hashArgOptLists->{"ArgList"}}, @{$arguments}); }
72 if (defined $options) { push(@{$hashArgOptLists->{"OptList"}}, $options); }
73
74 my $self = new UnknownPlug($pluginlist, $inputargs, $hashArgOptLists);
75
76 return bless $self, $class;
77}
78
79
80# do plugin specific processing of doc_obj
81sub read
82{
83 my $self = shift (@_);
84 my ($pluginfo, $base_dir, $file, $metadata, $processor, $maxdocs, $total_count, $gli) = @_;
85
86 my $outhandle = $self->{'outhandle'};
87
88 #check process and block exps, smart block, etc
89 my ($block_status,$filename) = $self->read_block(@_);
90 return $block_status if ((!defined $block_status) || ($block_status==0));
91
92 # Report that we're processing the file
93 print STDERR "<Processing n='$file' p='RealMediaPlug'>\n" if ($gli);
94 print $outhandle "RealMediaPlug: processing $file\n"
95 if ($self->{'verbosity'}) > 1;
96
97 # create a new index document
98 my $doc_obj = new doc ($filename, "indexed_doc");
99 if ($processor->{'OIDtype'} =~ /^(assigned|dirname)$/) {
100 $doc_obj->set_OIDtype ($processor->{'OIDtype'}, $processor->{'OIDmetadata'});
101 }
102 else {
103 $doc_obj->set_OIDtype ("incremental"); # this is done to avoid hashing content of file
104 }
105 my $top_section = $doc_obj->get_top_section();
106
107 #if there's a leading directory name, eat it...
108 $file =~ s/^.*[\/\\]//;
109
110 my $url = $file;
111
112 # Source (filename) to be consistent with other plugins
113 $doc_obj->add_metadata($top_section, "Source", $url);
114
115
116 my $text = "";
117 my $real_media = rm::Header::PurePerl->new($filename);
118 foreach my $key (keys %{$real_media->info})
119 {
120 my $value = $real_media->info->{$key};
121 $doc_obj->add_metadata($top_section, $key, $value);
122 $text .= "$key: $value\n";
123 }
124
125 $doc_obj->add_utf8_text($top_section, "<pre>\n$text\n</pre>");
126
127 # srclink
128 $doc_obj->add_metadata($top_section, "FileFormat", "RealMedia");
129 $doc_obj->add_metadata($top_section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[Source]\">");
130 $doc_obj->add_metadata($top_section, "/srclink", "</a>");
131 # srcicon (need to include "irmvideo.gif" in the greenstone images directory
132 $doc_obj->add_metadata($top_section, "srcicon", "<img src=\"_httpprefix_/images/irmvideo.gif\" title=\"Download\" border=0>");
133
134 # Add the actual file as an associated file
135 $doc_obj->associate_file($filename, $file, "RealMedia", $top_section);
136
137 # include any metadata passed in from previous plugins
138 my $section = $doc_obj->get_top_section();
139 $self->extra_metadata ($doc_obj, $section, $metadata);
140
141 # do plugin specific processing of doc_obj
142 return undef unless defined ($self->process (\$text, $pluginfo, $base_dir, $file, $metadata, $doc_obj));
143
144 # do any automatic metadata extraction
145 $self->auto_extract_metadata($doc_obj);
146
147 # add an OID
148 $doc_obj->set_OID();
149
150 # process the document
151 $processor->process($doc_obj);
152
153 $self->{'num_processed'}++;
154 return 1;
155}
156
1571;
Note: See TracBrowser for help on using the repository browser.