[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 |
|
---|
| 27 | package MusicIRPlugin;
|
---|
| 28 |
|
---|
| 29 | use BasePlugin;
|
---|
| 30 | use jAudioExtractor;
|
---|
[22439] | 31 | use jSongMinerExtractor;
|
---|
[22430] | 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 {
|
---|
[22439] | 40 | @MusicIRPlugin::ISA = ('BasePlugin', 'jAudioExtractor', 'jSongMinerExtractor');
|
---|
[22430] | 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" },
|
---|
[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 |
|
---|
| 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 |
|
---|
[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 |
|
---|
| 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(@_);
|
---|
[22439] | 104 | $self->jSongMinerExtractor::begin(@_);
|
---|
[22430] | 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 |
|
---|
| 109 | # do plugin specific processing of doc_obj
|
---|
| 110 | sub process {
|
---|
| 111 | my $self = shift (@_);
|
---|
| 112 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | my $outhandle = $self->{'outhandle'};
|
---|
| 116 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
| 117 |
|
---|
| 118 | if ($self->{'compute_mir_features'} eq "true")
|
---|
| 119 | {
|
---|
| 120 | my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
|
---|
| 121 | my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
|
---|
| 122 |
|
---|
| 123 | my $features_filename = $self->compute_features($filename_full_path);
|
---|
| 124 | my ($features_ext) = ($features_filename =~ m/\.([^.]+)$/);
|
---|
| 125 |
|
---|
| 126 | my $top_section = $doc_obj->get_top_section();
|
---|
| 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 |
|
---|
[22439] | 134 |
|
---|
[22430] | 135 | #we have no text - adds dummy text and NoText metadata
|
---|
| 136 | $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
|
---|
| 137 |
|
---|
| 138 | return 1;
|
---|
| 139 |
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[22439] | 142 | sub post_process_doc_obj {
|
---|
| 143 | my $self = shift (@_);
|
---|
| 144 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
[22430] | 145 |
|
---|
[22439] | 146 | my $outhandle = $self->{'outhandle'};
|
---|
| 147 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
| 148 |
|
---|
| 149 | if ($self->{'retrieve_mir_metadata'} eq "true") {
|
---|
| 150 | my $top_section = $doc_obj->get_top_section();
|
---|
| 151 | my $id3_titles = $doc_obj->get_metadata($top_section,"ID3.Title");
|
---|
| 152 |
|
---|
| 153 | my $id3_title = shift @$id3_titles || "Unknown";
|
---|
| 154 |
|
---|
| 155 | my $id3_artists = $doc_obj->get_metadata($top_section,"ID3.Artist");
|
---|
| 156 | my $id3_artist = shift @$id3_artists || "Unkown";
|
---|
| 157 |
|
---|
[22468] | 158 | my ($metadata_acexml_filename,$metadata_txt_filename)
|
---|
| 159 | = $self->retrieve_metadata($filename_full_path,$id3_title,$id3_artist);
|
---|
| 160 |
|
---|
| 161 | if (-e $metadata_txt_filename) {
|
---|
| 162 | $self->parse_txt_metadata($doc_obj,$metadata_txt_filename);
|
---|
| 163 | }
|
---|
| 164 |
|
---|
| 165 |
|
---|
[22439] | 166 | }
|
---|
| 167 |
|
---|
| 168 |
|
---|
| 169 | return 1;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 |
|
---|
[22430] | 173 | 1;
|
---|
| 174 |
|
---|
| 175 |
|
---|
| 176 |
|
---|