Show
Ignore:
Timestamp:
21.07.2010 16:31:05 (9 years ago)
Author:
davidb
Message:

Connecting plugin to jSongMiner *and* then setting metadata for the values generated in the x_metadata.txt file

Location:
gs2-extensions/music-ir/trunk/perllib/plugins
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • gs2-extensions/music-ir/trunk/perllib/plugins/MusicIRPlugin.pm

    r22439 r22468  
    156156    my $id3_artist = shift @$id3_artists || "Unkown"; 
    157157 
    158     my $metadata_txt_filename = $self->retrieve_metadata($filename_full_path,$id3_title,$id3_artist); 
     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 
    159166    } 
    160167 
  • gs2-extensions/music-ir/trunk/perllib/plugins/jSongMinerExtractor.pm

    r22441 r22468  
    3131 
    3232use Cwd; 
     33use URI::Escape; 
    3334 
    3435use strict; 
     
    7778} 
    7879 
     80sub urlEncode{ 
     81    # ARG 1: $to_encode is the string to URL encode 
     82    my ($to_encode) = @_; 
     83    return uri_escape($to_encode); 
     84} 
     85 
     86# URL Decode the given string 
     87sub urlDecode{ 
     88    # ARG 1: $to_decode is the string to URL decode 
     89    my ($to_decode) = @_; 
     90    return uri_unescape($to_decode); 
     91} 
     92 
     93sub parse_txt_metadata 
     94{ 
     95    my $self = shift @_; 
     96    my ($doc_obj,$target_txt_file_path) = @_; 
     97 
     98    if (open(MIN,"<$target_txt_file_path")) { 
     99 
     100    my ($md_name, $md_value); 
     101 
     102    while (defined($md_name=<MIN>) && defined($md_value=<MIN>)) { 
     103 
     104        chomp $md_name; 
     105        chomp $md_value; 
     106 
     107        my $top_section=$doc_obj->get_top_section(); 
     108 
     109        $md_name =~ s/\+//g; 
     110        $md_value =~ s/\+//g; 
     111         
     112        $md_name = urlDecode($md_name); 
     113        $md_value = urlDecode($md_value); 
     114 
     115        # $md_name =~ s/\s+//g; 
     116        $md_name =~ s/\(.*?\)$//; 
     117        $md_name =~ s/Last\.FM/LastFM/g; 
     118        $md_name =~ s/:/^/g; 
     119        $md_name =~ s/(API)?\^/./; 
     120 
     121        $doc_obj->add_metadata($top_section,$md_name,$md_value); 
     122    } 
     123 
     124    close(MIN); 
     125    } 
     126    else { 
     127    print STDERR "Error: Failed to open $target_txt_file_path\n"; 
     128    print STDERR "       !$\n"; 
     129    } 
     130} 
     131 
     132 
    79133sub retrieve_metadata 
    80134{ 
     
    91145    $self->init_cache_for_file($source_file_path); 
    92146 
    93     my $target_file_path; 
     147    my $target_txt_file_path; 
     148    my $target_acexml_file_path; 
     149 
    94150    if ($self->{'enable_cache'}) { 
    95151    my $cached_dir = $self->{'cached_dir'}; 
    96152    my $file_root = $self->{'cached_file_root'}; 
    97153 
    98     my $target_file = "${file_root}_metadata.txt"; 
    99  
    100     $target_file_path = &util::filename_cat($cached_dir,$target_file); 
     154    my $target_txt_file = "${file_root}_metadata.txt"; 
     155    my $target_acexml_file = "${file_root}.xml"; 
     156 
     157    $target_txt_file_path = &util::filename_cat($cached_dir,$target_txt_file); 
     158    $target_acexml_file_path = &util::filename_cat($cached_dir,$target_acexml_file); 
    101159    } 
    102160    else { 
    103     $target_file_path = &util::get_tmp_filename("_metadata.txt"); 
     161    $target_txt_file_path = &util::get_tmp_filename("_metadata.txt"); 
     162    $target_acexml_file_path = &util::get_tmp_filename(".xml"); 
    104163    } 
    105164 
     
    119178    $jsongminer_cmd .= " -title \"$id3_title\""; 
    120179    $jsongminer_cmd .= " -artist \"$id3_artist\""; 
    121     $jsongminer_cmd .= " -file \"$source_file_path\""; 
     180    $jsongminer_cmd .= " -audio \"$source_file_path\""; 
     181    $jsongminer_cmd .= " -savefile \"$target_txt_file_path\""; 
     182##  $jsongminer_cmd .= " -saveacefile \"$target_acexml_file_path\""; 
    122183     
    123184    if ($verbosity>2) { 
     
    127188     
    128189    my $print_info = { 'message_prefix' => "jSongMiner", 
    129                'message' => "Retrieving audio metadata for $source_file_no_path" }; 
     190               'message' => "jSongMinerExtractor: Retrieving audio metadata for $source_file_no_path" }; 
    130191     
    131192    my ($regenerated,$result,$had_error)  
    132         = $self->autorun_general_cmd($jsongminer_cmd,$source_file_path,$target_file_path,$print_info); 
     193        = $self->autorun_general_cmd($jsongminer_cmd,$source_file_path,$target_txt_file_path,$print_info); 
    133194     
    134195    if ($verbosity>2) { 
     
    143204    chdir($store_cwd); 
    144205 
    145          
    146     return ($target_file_path); 
     206    return ($target_acexml_file_path,$target_txt_file_path); 
    147207} 
    148208