Changeset 9 in flacrip for trunk/MusicBrainz.pm
- Timestamp:
- 08/23/13 11:43:11 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MusicBrainz.pm
r8 r9 70 70 $info{MUSICBRAINZ_ALBUMID} = $xpath->findvalue('@id', $release)->value; 71 71 $info{ALBUM} = $xpath->findvalue('title', $release)->value; 72 $info{ALBUMARTIST} = $xpath->findvalue('artist-credit/name-credit/artist/name', $release)->value; 73 $info{ALBUMARTISTSORT} = $xpath->findvalue('artist-credit/name-credit/artist/sort-name', $release)->value; 72 @info{qw{ALBUMARTIST ALBUMARTISTSORT}} = get_artist_credits($xpath, $release); 74 73 $info{DATE} = $xpath->findvalue('date', $release)->value; 75 74 $info{ORIGINALDATE} = $xpath->findvalue('release-group/first-release-date', $release)->value; … … 78 77 my ($medium) = $xpath->findnodes("medium-list/medium[disc-list/disc/\@id='$discid']", $release); 79 78 80 my $ua = LWP::UserAgent->new;79 #my $ua = LWP::UserAgent->new; 81 80 my $tracknum = 1; 82 81 for my $track_node ($xpath->findnodes('track-list/track', $medium)) { 83 82 my $prefix = sprintf('TRACK%02d', $tracknum); 84 my $track_mbid = $info{"$prefix.MUSICBRAINZ_TRACKID"} = $xpath->findvalue('@id', $track_node)->value; 85 my $recording_mbid = $info{"$prefix.MUSICBRAINZ_RECORDINGID"} = $xpath->findvalue('recording/@id', $track_node)->value; 86 87 $info{"$prefix.TITLE"} = $xpath->findvalue('recording/title', $track_node)->value; 88 89 # use the MusicBrainz join phrase to build up the multiple artist credits 90 my ($credit, $sort_credit) = ('', ''); 91 for my $credit_node ($xpath->findnodes('recording/artist-credit/name-credit', $track_node)) { 92 $credit .= $xpath->findvalue('concat(artist/name, @joinphrase)', $credit_node)->value; 93 $sort_credit .= $xpath->findvalue('concat(artist/sort-name, @joinphrase)', $credit_node)->value; 94 } 95 $info{"$prefix.ARTIST"} = $credit; 96 $info{"$prefix.ARTISTSORT"} = $sort_credit; 83 84 $info{"$prefix.MUSICBRAINZ_TRACKID"} = $xpath->findvalue('@id', $track_node)->value; 85 86 my ($recording) = $xpath->findnodes('recording', $track_node); 87 $info{"$prefix.MUSICBRAINZ_RECORDINGID"} = $xpath->findvalue('@id', $recording)->value; 88 $info{"$prefix.TITLE"} = $xpath->findvalue('title', $recording)->value; 89 @info{"$prefix.ARTIST", "$prefix.ARTISTSORT"} = get_artist_credits($xpath, $recording); 97 90 98 91 $info{TRACKS}[$tracknum]{TITLE} = $info{"$prefix.TITLE"}; 99 92 $info{TRACKS}[$tracknum]{ARTIST} = $info{"$prefix.ARTIST"}; 100 93 $info{TRACKS}[$tracknum]{ARTISTSORT} = $info{"$prefix.ARTISTSORT"}; 94 101 95 #my $uri = URI->new("http://musicbrainz.org/ws/2/recording/$recording_mbid"); 102 96 #$uri->query_form(inc => 'artists'); … … 110 104 111 105 return \%info; 106 } 107 108 sub get_artist_credits { 109 my ($xpath, $context_node) = @_; 110 111 # use the MusicBrainz join phrase to build up the multiple artist credits 112 my ($credit, $sort_credit) = ('', ''); 113 for my $credit_node ($xpath->findnodes('artist-credit/name-credit', $context_node)) { 114 $credit .= $xpath->findvalue('concat(artist/name, @joinphrase)', $credit_node)->value; 115 $sort_credit .= $xpath->findvalue('concat(artist/sort-name, @joinphrase)', $credit_node)->value; 116 } 117 118 return ($credit, $sort_credit); 112 119 } 113 120
Note: See TracChangeset
for help on using the changeset viewer.