Changeset 8 in flacrip
- Timestamp:
- 08/23/13 10:45:51 (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MusicBrainz.pm
r5 r8 5 5 6 6 our @ISA = qw{Exporter}; 7 our @EXPORT = qw{get_musicbrainz_info };7 our @EXPORT = qw{get_musicbrainz_info lookup_release}; 8 8 9 9 #use WebService::MusicBrainz; … … 36 36 my %info; 37 37 38 #TODO: deprecate the old MBZ tag name 38 39 $info{MBZ_DISCID} = $discid; 40 $info{MUSICBRAINZ_DISCID} = $discid; 39 41 40 42 my $xpath = XML::XPath->new(); … … 44 46 45 47 # 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 46 67 # 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; 54 76 55 77 # select the proper medium (important for multidisc releases) … … 60 82 for my $track_node ($xpath->findnodes('track-list/track', $medium)) { 61 83 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 64 87 $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 66 98 $info{TRACKS}[$tracknum]{TITLE} = $info{"$prefix.TITLE"}; 67 99 $info{TRACKS}[$tracknum]{ARTIST} = $info{"$prefix.ARTIST"}; 100 $info{TRACKS}[$tracknum]{ARTISTSORT} = $info{"$prefix.ARTISTSORT"}; 68 101 #my $uri = URI->new("http://musicbrainz.org/ws/2/recording/$recording_mbid"); 69 102 #$uri->query_form(inc => 'artists'); -
trunk/mbz
r5 r8 38 38 39 39 if ($GET_RELEASE_ID) { 40 print "$$info{ RELEASE_MBID}\n";40 print "$$info{MUSICBRAINZ_ALBUMID}\n"; 41 41 } else { 42 42 for my $key (sort keys %{ $info }) {
Note: See TracChangeset
for help on using the changeset viewer.