source: gs2-extensions/music-ir/trunk/perllib/plugins/jSongMinerExtractor.pm@ 22439

Last change on this file since 22439 was 22439, checked in by davidb, 14 years ago

Initial work on supporting jSongMiner

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1###########################################################################
2#
3# jSongMinerExtractor - helper plugin that identifies audio through
4# external web services based on either an audio
5# computed fingerprint or ID3 title and album
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 (C) 2010 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###########################################################################
28package jSongMinerExtractor;
29
30use BaseMediaConverter;
31
32use Cwd;
33
34use strict;
35no strict 'refs'; # allow filehandles to be variables and viceversa
36
37
38BEGIN {
39 @jSongMinerExtractor::ISA = ('BaseMediaConverter');
40}
41
42
43my $arguments = [
44 { 'name' => "track_identification",
45 'desc' => "{jSongMinerExtractor.track_identification}",
46 'type' => "enum",
47 'list' => [{'name' => "Fingerprint then ID3 tags", 'desc' => "{jSongMinerExtractor.fingerprint_first}"},
48 {'name' => "ID3 tags only", 'desc' => "{jSongMinerExtractor.only_ids}"},
49 {'name' => "Disabled", 'desc' => "{jSongMinerExtractor.off}"} ],
50 'deft' => 'Fingerprint then ID3 tags',
51 'reqd' => "no" }
52 ];
53
54my $options = { 'name' => "jSongMinerExtractor",
55 'desc' => "{jSongMinerExtractor.desc}",
56 'abstract' => "yes",
57 'inherits' => "yes",
58 'args' => $arguments };
59
60sub new {
61 my ($class) = shift (@_);
62 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
63 push(@$pluginlist, $class);
64
65 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
66 push(@{$hashArgOptLists->{"OptList"}},$options);
67
68 my $self = new BaseMediaConverter($pluginlist, $inputargs, $hashArgOptLists, 1);
69
70 # Set controlling variables
71 my $gsdl_home = $ENV{'GSDLHOME'};
72 my $music_ir_home = $ENV{'GEXT_MUSICIR'};
73
74 return bless $self, $class;
75}
76
77sub retrieve_metadata
78{
79 my $self = shift(@_);
80 my ($source_file_path,$id3_title,$id3_artist,$convert_options) = @_;
81
82 $convert_options = "" if (!defined $convert_options);
83
84 my $outhandle = $self->{'outhandle'};
85 my $verbosity = $self->{'verbosity'};
86
87 my $source_file_no_path = &File::Basename::basename($source_file_path);
88
89 $self->init_cache_for_file($source_file_path);
90
91 my $target_file_path;
92 if ($self->{'enable_cache'}) {
93 my $cached_dir = $self->{'cached_dir'};
94 my $file_root = $self->{'cached_file_root'};
95
96 my $target_file = "${file_root}_metadata.txt";
97
98 $target_file_path = &util::filename_cat($cached_dir,$target_file);
99 }
100 else {
101 $target_file_path = &util::get_tmp_filename("_metadata.txt");
102 }
103
104 my $jsongminer_cmd = "java -Xmx1024M -jar jSongMinor.jar $convert_options \"$id3_title\" \"$id3_artist\"";
105
106 print STDERR "*** cmd: $jsongminer_cmd\n";
107
108 my $print_info = { 'message_prefix' => "jSongMiner",
109 'message' => "Retrieving audio metadata for $source_file_no_path" };
110
111# my ($regenerated,$result,$had_error)
112# = $self->autorun_general_cmd($jsongminer_cmd,$source_file_path,$target_file_path,$print_info);
113
114 return ($target_file_path);
115}
116
117
118
119
1201;
Note: See TracBrowser for help on using the repository browser.