1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # AudioPlugin.pm -- Plugin for MP3 files (MPEG audio layer 3).
|
---|
4 | #
|
---|
5 | # A component of the Greenstone digital library software from the New
|
---|
6 | # Zealand Digital Library Project at the University of Waikato, New
|
---|
7 | # Zealand.
|
---|
8 | #
|
---|
9 | # Copyright (C) 2001 New Zealand Digital Library Project
|
---|
10 | #
|
---|
11 | # This program is free software; you can redistribute it and/or modify
|
---|
12 | # it under the terms of the GNU General Public License as published by
|
---|
13 | # the Free Software Foundation; either version 2 of the License, or
|
---|
14 | # (at your option) any later version.
|
---|
15 | #
|
---|
16 | # This program is distributed in the hope that it will be useful, but
|
---|
17 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | # General Public License for more details.
|
---|
20 | #
|
---|
21 | # You should have received a copy of the GNU General Public License
|
---|
22 | # along with this program; if not, write to the Free Software
|
---|
23 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | #
|
---|
25 | ###########################################################################
|
---|
26 |
|
---|
27 |
|
---|
28 | package AudioPlugin;
|
---|
29 |
|
---|
30 | use BasePlugin;
|
---|
31 | use AudioConverter;
|
---|
32 |
|
---|
33 | use strict;
|
---|
34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
35 | ###no strict 'subs';
|
---|
36 |
|
---|
37 | sub BEGIN {
|
---|
38 | @AudioPlugin::ISA = ('BasePlugin', 'AudioConverter');
|
---|
39 | }
|
---|
40 |
|
---|
41 | my $arguments =
|
---|
42 | [ { 'name' => "process_exp",
|
---|
43 | 'desc' => "{BasePlugin.process_exp}",
|
---|
44 | 'type' => "regexp",
|
---|
45 | 'deft' => &get_default_process_exp(),
|
---|
46 | 'reqd' => "no" } ];
|
---|
47 |
|
---|
48 | my $options = { 'name' => "AudioPlugin",
|
---|
49 | 'desc' => "{AudioPlugin.desc}",
|
---|
50 | 'abstract' => "no",
|
---|
51 | 'inherits' => "yes",
|
---|
52 | 'args' => $arguments };
|
---|
53 |
|
---|
54 | sub new {
|
---|
55 | my ($class) = shift (@_);
|
---|
56 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
57 | push(@$pluginlist, $class);
|
---|
58 |
|
---|
59 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
60 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
61 |
|
---|
62 | new AudioConverter($pluginlist, $inputargs, $hashArgOptLists);
|
---|
63 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
64 |
|
---|
65 | return bless $self, $class;
|
---|
66 | }
|
---|
67 |
|
---|
68 | sub init {
|
---|
69 | my $self = shift (@_);
|
---|
70 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
71 |
|
---|
72 | $self->SUPER::init(@_);
|
---|
73 | $self->AudioConverter::init();
|
---|
74 | }
|
---|
75 |
|
---|
76 | sub get_default_process_exp
|
---|
77 | {
|
---|
78 | my $self = shift (@_);
|
---|
79 | if (!defined $self->{'stored_process_re'}) {
|
---|
80 |
|
---|
81 | my $static_fallback_re = q^(?i)\.(aif?|au|mp3|ogg|snd|wav)$^;
|
---|
82 |
|
---|
83 | if ($self->{'audio_conversion_available'}) {
|
---|
84 | # Haven't run sox before to see what formats it supports
|
---|
85 | # => do so now
|
---|
86 |
|
---|
87 | my $sox_output = `sox -h`;
|
---|
88 | my ($output_list) = ($sox_output =~ m/SUPPORTED FILE FORMATS:\s*(.*)$/m);
|
---|
89 | if (defined $output_list && ($output_list ne "")) {
|
---|
90 | $output_list =~ s/\s+/,/g;
|
---|
91 |
|
---|
92 | $self->{'stored_process_re'} = $output_list;
|
---|
93 | }
|
---|
94 | else {
|
---|
95 | $self->{'stored_process_re'} = $static_fallback_re;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | else {
|
---|
99 | # Audio format conversion isn't supported, but (as for images)
|
---|
100 | # source format might very well be OK for inclusion in web
|
---|
101 | # page produced for document
|
---|
102 |
|
---|
103 | $self->{'stored_process_re'} = $static_fallback_re;
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | print STDERR "*** returning: $self->{'stored_process_re'}\n";
|
---|
108 |
|
---|
109 | return $self->{'stored_process_re'};
|
---|
110 |
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | # do plugin specific processing of doc_obj
|
---|
116 | sub process {
|
---|
117 | my $self = shift (@_);
|
---|
118 | # options??
|
---|
119 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
120 |
|
---|
121 |
|
---|
122 | my $outhandle = $self->{'outhandle'};
|
---|
123 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
124 |
|
---|
125 | my $top_section = $doc_obj->get_top_section();
|
---|
126 |
|
---|
127 | if ($self->{'audio_conversion_available'} == 1) {
|
---|
128 | $self->generate_audio($filename_full_path, $filename_no_path, $doc_obj, $top_section); # should we check the return value?
|
---|
129 | } else {
|
---|
130 | # do some basic stuff
|
---|
131 | # associate the audio, fileformat, mimetype, srclink, srcicon
|
---|
132 | # do this if sox not installed. but also if generate hasn't worked??
|
---|
133 | }
|
---|
134 | #we have no text - adds dummy text and NoText metadata
|
---|
135 | $self->add_dummy_text($doc_obj, $top_section);
|
---|
136 |
|
---|
137 |
|
---|
138 | # *****
|
---|
139 | # Does the code currently associate the original file with document?
|
---|
140 | # How about it's MIME type. This might be a bit tricky to work out
|
---|
141 | # for a dynamically generated list
|
---|
142 |
|
---|
143 | return 1;
|
---|
144 |
|
---|
145 | }
|
---|
146 |
|
---|
147 |
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | 1;
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
|
---|
162 |
|
---|