[7911] | 1 | ###########################################################################
|
---|
| 2 | #
|
---|
| 3 | # OggVorbisPlug.pm -- A plugin for Ogg Vorbis audio files
|
---|
| 4 | #
|
---|
| 5 | # Original code by Christy Kuo
|
---|
| 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 1999-2004 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 OggVorbisPlugin;
|
---|
[7911] | 30 |
|
---|
| 31 |
|
---|
[15872] | 32 | use BasePlugin;
|
---|
[7911] | 33 | use Ogg::Vorbis::Header::PurePerl;
|
---|
| 34 |
|
---|
[10254] | 35 | use strict;
|
---|
| 36 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
[15872] | 37 | no strict 'subs';
|
---|
[7911] | 38 |
|
---|
| 39 | sub BEGIN {
|
---|
[15872] | 40 | @OggVorbisPlugin::ISA = ('BasePlugin');
|
---|
[7911] | 41 | }
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | my $arguments =
|
---|
| 45 | [ { 'name' => "process_exp",
|
---|
[15872] | 46 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[7911] | 47 | 'type' => "string",
|
---|
| 48 | 'deft' => &get_default_process_exp(),
|
---|
| 49 | 'reqd' => "no" },
|
---|
| 50 | { 'name' => "add_technical_metadata",
|
---|
[15872] | 51 | 'desc' => "{OggVorbisPlugin.add_technical_metadata}",
|
---|
[7911] | 52 | 'type' => "flag",
|
---|
[18320] | 53 | 'deft' => "" },
|
---|
| 54 | { 'name' => "file_rename_method",
|
---|
| 55 | 'desc' => "{BasePlugin.file_rename_method}",
|
---|
| 56 | 'type' => "enum",
|
---|
| 57 | 'deft' => &get_default_file_rename_method(), # by default rename imported files and assoc files using this encoding
|
---|
| 58 | 'list' => $BasePlugin::file_rename_method_list,
|
---|
| 59 | 'reqd' => "no"
|
---|
| 60 | } ];
|
---|
[7911] | 61 |
|
---|
[15872] | 62 | my $options = { 'name' => "OggVorbisPlugin",
|
---|
| 63 | 'desc' => "{OggVorbisPlugin.desc}",
|
---|
[7911] | 64 | 'inherits' => "yes",
|
---|
[11676] | 65 | 'abstract' => "no",
|
---|
[7911] | 66 | 'args' => $arguments };
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | # This plugin processes exported Ogg Vorbis files with the suffix ".ogg"
|
---|
| 70 | sub get_default_process_exp
|
---|
| 71 | {
|
---|
| 72 | return q^(?i)(\.ogg)$^;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[18320] | 75 | # rename imported media files using base64 encoding by default
|
---|
| 76 | # so that the urls generated will always work with external apps
|
---|
| 77 | sub get_default_file_rename_method() {
|
---|
| 78 | return "base64";
|
---|
| 79 | }
|
---|
[7911] | 80 |
|
---|
| 81 | sub new
|
---|
| 82 | {
|
---|
[10218] | 83 | my ($class) = shift(@_);
|
---|
| 84 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 85 | push(@$pluginlist, $class);
|
---|
| 86 |
|
---|
[15872] | 87 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 88 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[10218] | 89 |
|
---|
[15872] | 90 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[10218] | 91 |
|
---|
[7911] | 92 | return bless $self, $class;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[17026] | 95 | # we don't want to hash on the file
|
---|
| 96 | sub get_oid_hash_type {
|
---|
| 97 | my $self = shift (@_);
|
---|
| 98 | return "hash_on_ga_xml";
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[15872] | 101 | sub process
|
---|
[7911] | 102 | {
|
---|
| 103 | my $self = shift (@_);
|
---|
[15872] | 104 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[7911] | 105 |
|
---|
[16392] | 106 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
[13543] | 107 |
|
---|
[15872] | 108 | my $top_section = $doc_obj->get_top_section();
|
---|
[7911] | 109 | # Extract metadata
|
---|
[15872] | 110 | my $ogg = Ogg::Vorbis::Header::PurePerl->new($filename_full_path);
|
---|
[7911] | 111 |
|
---|
| 112 | # Comments added to the file
|
---|
| 113 | foreach my $key ($ogg->comment_tags())
|
---|
| 114 | {
|
---|
| 115 | # Convert key to title case
|
---|
| 116 | my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
|
---|
| 117 | foreach my $value ($ogg->comment($key))
|
---|
| 118 | {
|
---|
| 119 | if (defined $value && $value ne "") {
|
---|
[15872] | 120 | $doc_obj->add_metadata($top_section, $keytc, $value);
|
---|
[7911] | 121 | }
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | # Technical data (optional)
|
---|
| 126 | if ($self->{'add_technical_metadata'}) {
|
---|
| 127 | foreach my $key (keys %{$ogg->info})
|
---|
| 128 | {
|
---|
| 129 | # Convert key to title case
|
---|
| 130 | my $keytc = uc(substr($key, 0, 1)) . substr($key, 1, length($key));
|
---|
| 131 | my $value = $ogg->info->{$key};
|
---|
| 132 | if (defined $value && $value ne "") {
|
---|
[15872] | 133 | $doc_obj->add_metadata($top_section, $keytc, $value);
|
---|
[7911] | 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
| 137 |
|
---|
[15872] | 138 | $doc_obj->add_metadata ($top_section, "FileFormat", "OggVorbis");
|
---|
[21760] | 139 | #$doc_obj->add_metadata ($top_section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
|
---|
| 140 | #$doc_obj->add_metadata ($top_section, "/srclink", "</a>");
|
---|
| 141 | $doc_obj->add_metadata ($section, "srclink_file", "[SourceFile]");
|
---|
[21746] | 142 | $doc_obj->add_metadata ($top_section, "srcicon", "_iconogg_");
|
---|
[7911] | 143 |
|
---|
[15911] | 144 | # add dummy text and NoText metadata which can be used to suppress the dummy text
|
---|
| 145 | $self->add_dummy_text($doc_obj, $top_section);
|
---|
[14117] | 146 |
|
---|
[7911] | 147 | # Add the actual file as an associated file
|
---|
[16960] | 148 | my $assoc_file = $doc_obj->add_assocfile_from_sourcefile();
|
---|
[16957] | 149 | $doc_obj->associate_file($filename_full_path, $assoc_file, "VORBIS", $top_section);
|
---|
[7911] | 150 |
|
---|
| 151 | }
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | 1;
|
---|