Changeset 9 in flacrip


Ignore:
Timestamp:
08/23/13 11:43:11 (11 years ago)
Author:
peter
Message:
  • encapsulated the code to get artist name and sort name into get_artist_credits() function
  • use get_artist_credits() to get the album artist names in addition to just the recording artist names
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MusicBrainz.pm

    r8 r9  
    7070    $info{MUSICBRAINZ_ALBUMID} = $xpath->findvalue('@id', $release)->value; 
    7171    $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); 
    7473    $info{DATE}                = $xpath->findvalue('date', $release)->value; 
    7574    $info{ORIGINALDATE}        = $xpath->findvalue('release-group/first-release-date', $release)->value; 
     
    7877    my ($medium) = $xpath->findnodes("medium-list/medium[disc-list/disc/\@id='$discid']", $release); 
    7978 
    80     my $ua = LWP::UserAgent->new; 
     79    #my $ua = LWP::UserAgent->new; 
    8180    my $tracknum = 1; 
    8281    for my $track_node ($xpath->findnodes('track-list/track', $medium)) { 
    8382        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); 
    9790 
    9891        $info{TRACKS}[$tracknum]{TITLE} = $info{"$prefix.TITLE"}; 
    9992        $info{TRACKS}[$tracknum]{ARTIST} = $info{"$prefix.ARTIST"}; 
    10093        $info{TRACKS}[$tracknum]{ARTISTSORT} = $info{"$prefix.ARTISTSORT"}; 
     94 
    10195        #my $uri = URI->new("http://musicbrainz.org/ws/2/recording/$recording_mbid"); 
    10296        #$uri->query_form(inc => 'artists'); 
     
    110104 
    111105    return \%info; 
     106} 
     107 
     108sub 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); 
    112119} 
    113120 
Note: See TracChangeset for help on using the changeset viewer.