Changeset 8 in flacrip for trunk/MusicBrainz.pm


Ignore:
Timestamp:
08/23/13 10:45:51 (11 years ago)
Author:
peter
Message:
  • use the VorbisComment style tag names in the info hash returned by MusicBrainz::get_musicbrainz_info()
  • use the MusicBrainz name credit join phrase to build the string where there are multiple artists
  • include the artist sort names in the returned info, as TRACKnn.ARTISTSORT keys, and ALBUMARTIST
  • added an applymeta script that applies the metadata listed in a file to a set of MP3 files
  • when loooking up a release, MusicBrainz::get_musicbrainz_info() prints the number of releases and some other debugging info to STDERR
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MusicBrainz.pm

    r5 r8  
    55 
    66our @ISA    = qw{Exporter}; 
    7 our @EXPORT = qw{get_musicbrainz_info}; 
     7our @EXPORT = qw{get_musicbrainz_info lookup_release}; 
    88 
    99#use WebService::MusicBrainz; 
     
    3636    my %info; 
    3737 
     38    #TODO: deprecate the old MBZ tag name 
    3839    $info{MBZ_DISCID} = $discid; 
     40    $info{MUSICBRAINZ_DISCID} = $discid; 
    3941 
    4042    my $xpath = XML::XPath->new(); 
     
    4446 
    4547    # get the release; if there is more than one, take the first one 
     48    my $release_count = $xpath->findvalue('count(//release)'); 
     49    my @releases = $xpath->findnodes('//release'); 
     50    my $base = 'http://musicbrainz.org/release/'; 
     51 
     52    my $i = 1; 
     53    #TODO: use this as the basis for an interactive menu to pick the correct release ID 
     54    warn "$release_count release(s) found matching $discid\n"; 
     55    for my $release (@releases) { 
     56        warn sprintf "%2d) $base%s %s %s (%s)\n",  
     57            $i++, 
     58            $xpath->findvalue('@id', $release)->value, 
     59            $xpath->findvalue('.//label-info/label/name', $release)->value, 
     60            $xpath->findvalue('.//label-info/catalog-number', $release)->value, 
     61            $xpath->findvalue('barcode', $release)->value; 
     62    } 
     63 
     64    # use the VorbisComment names from here http://musicbrainz.org/doc/MusicBrainz_Picard/Tags/Mapping 
     65 
     66    # use the first release by default 
    4667    # TODO: configurable release selection criteria 
    47     my $release_count = $xpath->findvalue('count(//release)'); 
    48     my ($release) = $xpath->findnodes('//release[1]'); 
    49     $info{RELEASE_MBID} = $xpath->findvalue('@id', $release)->value; 
    50     $info{ALBUM}        = $xpath->findvalue('title', $release)->value; 
    51     $info{ARTIST}       = $xpath->findvalue('artist-credit/name-credit/artist/name', $release)->value; 
    52  
    53     # TODO: get release date 
     68    my $release = $releases[0]; 
     69 
     70    $info{MUSICBRAINZ_ALBUMID} = $xpath->findvalue('@id', $release)->value; 
     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; 
     74    $info{DATE}                = $xpath->findvalue('date', $release)->value; 
     75    $info{ORIGINALDATE}        = $xpath->findvalue('release-group/first-release-date', $release)->value; 
    5476 
    5577    # select the proper medium (important for multidisc releases) 
     
    6082    for my $track_node ($xpath->findnodes('track-list/track', $medium)) { 
    6183        my $prefix = sprintf('TRACK%02d', $tracknum); 
    62         #$info{"$prefix.MB_TRACKID"} = $xpath->findvalue('@id', $track_node); 
    63         my $recording_mbid = $info{"$prefix.RECORDING_MBID"} = $xpath->findvalue('recording/@id', $track_node)->value; 
     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 
    6487        $info{"$prefix.TITLE"}          = $xpath->findvalue('recording/title', $track_node)->value; 
    65         $info{"$prefix.ARTIST"}         = $xpath->findvalue('recording/artist-credit/name-credit/artist/name', $track_node)->value || $info{ARTIST}; 
     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; 
     97 
    6698        $info{TRACKS}[$tracknum]{TITLE} = $info{"$prefix.TITLE"}; 
    6799        $info{TRACKS}[$tracknum]{ARTIST} = $info{"$prefix.ARTIST"}; 
     100        $info{TRACKS}[$tracknum]{ARTISTSORT} = $info{"$prefix.ARTISTSORT"}; 
    68101        #my $uri = URI->new("http://musicbrainz.org/ws/2/recording/$recording_mbid"); 
    69102        #$uri->query_form(inc => 'artists'); 
Note: See TracChangeset for help on using the changeset viewer.