source: gs2-extensions/music-ir-src/trunk/perllib/plugins/MusicIRPlugin.pm@ 28549

Last change on this file since 28549 was 28549, checked in by davidb, 10 years ago

Added mapping for ID3v1 genre number to text-string

File size: 5.8 KB
RevLine 
[22430]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
27package MusicIRPlugin;
28
29use BasePlugin;
30use jAudioExtractor;
[22439]31use jSongMinerExtractor;
[22430]32
33use strict;
34no strict 'refs'; # allow filehandles to be variables and viceversa
35no strict 'subs';
36
37use gsprintf 'gsprintf';
38
39sub BEGIN {
[22439]40 @MusicIRPlugin::ISA = ('BasePlugin', 'jAudioExtractor', 'jSongMinerExtractor');
[22430]41}
42
43my $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" },
[22439]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" },
[22430]59 { 'name' => "process_exp",
60 'desc' => "{BasePlugin.process_exp}",
61 'type' => "regexp",
62 'deft' => &get_default_process_exp(),
63 'reqd' => "no" }
64 ];
65
66my $options = { 'name' => "MusicIRPlugin",
67 'desc' => "{MusicIRPlugin.desc}",
68 'abstract' => "no",
69 'inherits' => "yes",
70 'args' => $arguments };
71
72
73
74sub 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
[22439]83 my $jae_self = new jAudioExtractor($pluginlist, $inputargs, $hashArgOptLists,1);
84 my $jsme_self = new jSongMinerExtractor($pluginlist, $inputargs, $hashArgOptLists,1);
[22430]85 my $base_self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
86
[22439]87 my $self = BasePlugin::merge_inheritance($jae_self,$jsme_self,$base_self);
[22430]88
89 return bless $self, $class;
90}
91
92sub get_default_process_exp {
93 my $self = shift (@_);
94
95 return q^(?i)(\.mp3|\.wave?|\.aif[fc]?|\.au|\.snd|\.og[ga])$^;
96}
97
98sub begin {
99 my $self = shift (@_);
100 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
101
102 $self->SUPER::begin(@_);
103 $self->jAudioExtractor::begin(@_);
[22439]104 $self->jSongMinerExtractor::begin(@_);
[22430]105}
106
107
108
[26276]109
110sub process_features {
[22430]111 my $self = shift (@_);
[26276]112 my ($base_dir, $file, $doc_obj) = @_;
[22430]113
114 my $outhandle = $self->{'outhandle'};
115 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
116
[24433]117 my $top_section = $doc_obj->get_top_section();
118
[22430]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
[26276]134}
135
136# do plugin specific processing of doc_obj
137sub 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);
[22439]144
[22430]145 #we have no text - adds dummy text and NoText metadata
146 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
147
[26276]148 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
[24433]149 $doc_obj->associate_file($filename_full_path, "audio.mp3", "audio/mpeg", $top_section);
150
[22430]151 return 1;
152
153}
154
[22439]155sub post_process_doc_obj {
156 my $self = shift (@_);
157 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
[22430]158
[22439]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();
[26276]164
[24433]165 my $id3_titles = $doc_obj->get_metadata($top_section,"ex.ID3.Title");
[26276]166 # my $id3_title = shift @$id3_titles || "Unknown";
167 my $id3_title = shift @$id3_titles || undef;
[22439]168
[24433]169 my $id3_artists = $doc_obj->get_metadata($top_section,"ex.ID3.Artist");
[26276]170 # my $id3_artist = shift @$id3_artists || "Unknown";
171 my $id3_artist = shift @$id3_artists || undef;
[22439]172
[22468]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
[28549]180 ### $self->check_for_existing_id3_genre($doc_obj);
181
[24433]182 $doc_obj->associate_file($metadata_acexml_filename, "jsongminer.xml",
183 "text/xml", $top_section);
[22439]184 }
185
186
187 return 1;
188}
189
190
[22430]1911;
192
193
194
Note: See TracBrowser for help on using the repository browser.