1 | ###########################################################################
|
---|
2 | #
|
---|
3 | # MusicIRPlugin.pm -- for augmenting audio/midi files with Music IR
|
---|
4 | # features and tags
|
---|
5 | # A component of the Greenstone digital library software
|
---|
6 | # from the New Zealand Digital Library Project at the
|
---|
7 | # University of Waikato, New Zealand.
|
---|
8 | #
|
---|
9 | # Copyright (C) 1999 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,
|
---|
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | # GNU 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 | package MusicIRPlugin;
|
---|
28 |
|
---|
29 | use BasePlugin;
|
---|
30 | use jAudioExtractor;
|
---|
31 | use jSongMinerExtractor;
|
---|
32 |
|
---|
33 | use strict;
|
---|
34 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
35 | no strict 'subs';
|
---|
36 |
|
---|
37 | use gsprintf 'gsprintf';
|
---|
38 |
|
---|
39 | sub BEGIN {
|
---|
40 | @MusicIRPlugin::ISA = ('BasePlugin', 'jAudioExtractor', 'jSongMinerExtractor');
|
---|
41 | }
|
---|
42 |
|
---|
43 | my $arguments =
|
---|
44 | [
|
---|
45 | { 'name' => "compute_mir_features",
|
---|
46 | 'desc' => "{BasePlugin.compute_mir_features}",
|
---|
47 | 'type' => "enum",
|
---|
48 | 'list' => [{'name' => "true", 'desc' => "{common.true}"},
|
---|
49 | {'name' => "false", 'desc' => "{common.false}"}],
|
---|
50 | 'deft' => "false",
|
---|
51 | 'reqd' => "no" },
|
---|
52 | { 'name' => "retrieve_mir_metadata",
|
---|
53 | 'desc' => "{BasePlugin.retrieve_mir_metadata}",
|
---|
54 | 'type' => "enum",
|
---|
55 | 'list' => [{'name' => "true", 'desc' => "{common.true}"},
|
---|
56 | {'name' => "false", 'desc' => "{common.false}"}],
|
---|
57 | 'deft' => "false",
|
---|
58 | 'reqd' => "no" },
|
---|
59 | { 'name' => "process_exp",
|
---|
60 | 'desc' => "{BasePlugin.process_exp}",
|
---|
61 | 'type' => "regexp",
|
---|
62 | 'deft' => &get_default_process_exp(),
|
---|
63 | 'reqd' => "no" }
|
---|
64 | ];
|
---|
65 |
|
---|
66 | my $options = { 'name' => "MusicIRPlugin",
|
---|
67 | 'desc' => "{MusicIRPlugin.desc}",
|
---|
68 | 'abstract' => "no",
|
---|
69 | 'inherits' => "yes",
|
---|
70 | 'args' => $arguments };
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | sub new {
|
---|
75 | my ($class) = shift (@_);
|
---|
76 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
77 | push(@$pluginlist, $class);
|
---|
78 |
|
---|
79 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
80 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
81 |
|
---|
82 |
|
---|
83 | my $jae_self = new jAudioExtractor($pluginlist, $inputargs, $hashArgOptLists,1);
|
---|
84 | my $jsme_self = new jSongMinerExtractor($pluginlist, $inputargs, $hashArgOptLists,1);
|
---|
85 | my $base_self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
86 |
|
---|
87 | my $self = BasePlugin::merge_inheritance($jae_self,$jsme_self,$base_self);
|
---|
88 |
|
---|
89 | return bless $self, $class;
|
---|
90 | }
|
---|
91 |
|
---|
92 | sub get_default_process_exp {
|
---|
93 | my $self = shift (@_);
|
---|
94 |
|
---|
95 | return q^(?i)(\.mp3|\.wave?|\.aif[fc]?|\.au|\.snd|\.og[ga])$^;
|
---|
96 | }
|
---|
97 |
|
---|
98 | sub begin {
|
---|
99 | my $self = shift (@_);
|
---|
100 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
101 |
|
---|
102 | $self->SUPER::begin(@_);
|
---|
103 | $self->jAudioExtractor::begin(@_);
|
---|
104 | $self->jSongMinerExtractor::begin(@_);
|
---|
105 | }
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | sub process_features {
|
---|
111 | my $self = shift (@_);
|
---|
112 | my ($base_dir, $file, $doc_obj) = @_;
|
---|
113 |
|
---|
114 | my $outhandle = $self->{'outhandle'};
|
---|
115 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
116 |
|
---|
117 | my $top_section = $doc_obj->get_top_section();
|
---|
118 |
|
---|
119 | if ($self->{'compute_mir_features'} eq "true")
|
---|
120 | {
|
---|
121 | my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
|
---|
122 | my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
|
---|
123 |
|
---|
124 | my $features_filename = $self->compute_features($filename_full_path);
|
---|
125 | my ($features_ext) = ($features_filename =~ m/\.([^.]+)$/);
|
---|
126 |
|
---|
127 |
|
---|
128 | my $mime_type = ($features_ext eq "arff") ? "text/plain" : "text/xml";
|
---|
129 | $doc_obj->associate_file($features_filename, "jaudio.$features_ext",
|
---|
130 | $mime_type, $top_section);
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|
134 | }
|
---|
135 |
|
---|
136 | # do plugin specific processing of doc_obj
|
---|
137 | sub process {
|
---|
138 | my $self = shift (@_);
|
---|
139 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
140 |
|
---|
141 | my $top_section = $doc_obj->get_top_section();
|
---|
142 |
|
---|
143 | $self->process_features($base_dir,$file,$doc_obj);
|
---|
144 |
|
---|
145 | #we have no text - adds dummy text and NoText metadata
|
---|
146 | $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
|
---|
147 |
|
---|
148 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
149 | $doc_obj->associate_file($filename_full_path, "audio.mp3", "audio/mpeg", $top_section);
|
---|
150 |
|
---|
151 | return 1;
|
---|
152 |
|
---|
153 | }
|
---|
154 |
|
---|
155 | sub post_process_doc_obj {
|
---|
156 | my $self = shift (@_);
|
---|
157 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
158 |
|
---|
159 | my $outhandle = $self->{'outhandle'};
|
---|
160 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
161 |
|
---|
162 | if ($self->{'retrieve_mir_metadata'} eq "true") {
|
---|
163 | my $top_section = $doc_obj->get_top_section();
|
---|
164 |
|
---|
165 | my $id3_titles = $doc_obj->get_metadata($top_section,"ex.ID3.Title");
|
---|
166 | # my $id3_title = shift @$id3_titles || "Unknown";
|
---|
167 | my $id3_title = shift @$id3_titles || undef;
|
---|
168 |
|
---|
169 | my $id3_artists = $doc_obj->get_metadata($top_section,"ex.ID3.Artist");
|
---|
170 | # my $id3_artist = shift @$id3_artists || "Unknown";
|
---|
171 | my $id3_artist = shift @$id3_artists || undef;
|
---|
172 |
|
---|
173 | my ($metadata_acexml_filename,$metadata_txt_filename)
|
---|
174 | = $self->retrieve_metadata($filename_full_path,$id3_title,$id3_artist);
|
---|
175 |
|
---|
176 | if (-e $metadata_txt_filename) {
|
---|
177 | $self->parse_txt_metadata($doc_obj,$metadata_txt_filename);
|
---|
178 | }
|
---|
179 |
|
---|
180 | ### $self->check_for_existing_id3_genre($doc_obj);
|
---|
181 |
|
---|
182 | $doc_obj->associate_file($metadata_acexml_filename, "jsongminer.xml",
|
---|
183 | "text/xml", $top_section);
|
---|
184 | }
|
---|
185 |
|
---|
186 |
|
---|
187 | return 1;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | 1;
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|