Changeset 3 in flacrip for trunk/flactrack
- Timestamp:
- 01/27/12 21:58:19 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/flactrack
r1 r3 8 8 9 9 use Getopt::Long; 10 use MusicBrainz; 10 11 11 12 GetOptions( … … 21 22 22 23 # for getting track metadata from MusicBrainz 23 my %info;24 my $info; 24 25 if ($TYPE eq 'mp3') { 25 26 require Audio::FLAC::Header; … … 32 33 #TODO: calculate TOC and DISCID from cuesheet if there is no MBZ_DISCID tag present 33 34 34 #TODO: use the functions in mbz instead of repeating them here) 35 %info = get_musicbrainz_info($discid); 35 $info = get_musicbrainz_info($discid); 36 36 } 37 37 … … 54 54 $cmd .= qq{| lame -b 192}; 55 55 # if there is track info, add it as ID3 tags 56 if ( %info) {57 my $track = $info {TRACKS}[$tracknum];56 if ($info) { 57 my $track = $info->{TRACKS}[$tracknum]; 58 58 $cmd .= sprintf q{ --tt %s --ta %s --tl %s --tn %d}, 59 quote($ $track{TITLE}),60 quote($ $track{ARTIST}),61 quote($info {ALBUM}),59 quote($track->{TITLE}), 60 quote($track->{ARTIST}), 61 quote($info->{ALBUM}), 62 62 $tracknum; 63 63 } … … 79 79 return qq{"$string"}; 80 80 } 81 82 83 # make the output terminal handle UTF-8 characters84 #binmode STDOUT, ':utf8';85 #my $info = get_musicbrainz_info($discid);86 #for my $key (sort keys %{ $info }) {87 # print "$key=$$info{$key}\n";88 #}89 90 sub lookup_release {91 my ($discid) = @_;92 my $ua = LWP::UserAgent->new;93 94 my $uri = URI->new('http://musicbrainz.org/ws/1/release/');95 $uri->query_form(type => 'xml', discid => $discid);96 97 my $res = $ua->get($uri);98 return $res->decoded_content;99 }100 101 sub get_musicbrainz_info {102 my ($discid) = @_;103 my %info;104 105 $info{MBZ_DISCID} = $discid;106 107 my $xpath = XML::XPath->new();108 109 $xpath->set_xml(lookup_release($discid));110 111 # TODO: check for more than 1 release?112 113 $info{MB_RELEASE_ID} = $xpath->findvalue('//release/@id');114 $info{ALBUM} = $xpath->findvalue('//release/title');115 $info{ARTIST} = $xpath->findvalue('//release/artist/name');116 $info{TRACKS} = [];117 118 # TODO: get release date119 120 my $tracknum = 1;121 for my $track_node ($xpath->findnodes('//track-list/track')) {122 $info{TRACKS}[$tracknum]{MB_TRACKID} = $xpath->findvalue('@id', $track_node);123 $info{TRACKS}[$tracknum]{TITLE} = $xpath->findvalue('title', $track_node);124 $info{TRACKS}[$tracknum]{ARTIST} = $xpath->findvalue('artist/name', $track_node) || $info{ARTIST};125 $tracknum++;126 }127 128 return %info;129 }
Note: See TracChangeset
for help on using the changeset viewer.