Changeset 40 in flacrip for trunk/lib/MusicBrainz.pm


Ignore:
Timestamp:
05/08/15 14:48:29 (9 years ago)
Author:
peter
Message:

If given a barcode, get_musicbrainz_info() will attempt to match a release on
the DiscID and the barcode.

  • get_musicbrainz_info() and select_release() take a hashref with discid and barcode keys
  • mbz script takes a --barcode argument; however, if --flac is given, it dtermines the barcode from the BARCODE tag in the FLAC file
  • added a barcode method to the DiscFlacFile class
  • corrected the call to Audio::FLAC::Header::info to a call to tags for the Vorbis tags
  • removed the superfluous getprops script
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/MusicBrainz.pm

    r31 r40  
    3333 
    3434sub select_release { 
    35     my ($xpath, $discid) = @_; 
     35    my ($xpath, $params) = @_; 
    3636 
    37     # get the release; if there is more than one, take the first one 
    38     my $release_count = $xpath->findvalue('count(//release)'); 
    39     my @releases = $xpath->findnodes('//release'); 
    40     my $base = 'http://musicbrainz.org/release/'; 
     37    my $discid = $params->{discid}; 
     38    my $barcode = $params->{barcode}; 
    4139 
    42     my $i = 1; 
    43     # present the user with an interactive menu to pick/confirm the correct release ID 
    44     warn "$release_count release(s) found matching $discid\n"; 
    45     for my $release (@releases) { 
    46         warn sprintf "%2d) $base%s %s %s (%s)\n",  
     40    if ($barcode) { 
     41        # try to pick the release automatically by the barcode 
     42        my @releases = $xpath->findnodes("//release[barcode='$barcode']"); 
     43        die "Found no releases with discid $discid and barcode $barcode\n" unless @releases; 
     44        die "Found more than one release with discid $discid and barcode $barcode\n" if @releases > 1; 
     45        return $releases[0]; 
     46    } else { 
     47        my $release_count = $xpath->findvalue('count(//release)'); 
     48        my @releases = $xpath->findnodes('//release'); 
     49        my $base = 'http://musicbrainz.org/release/'; 
     50 
     51        my $i = 1; 
     52        # present the user with an interactive menu to pick/confirm the correct release ID 
     53        warn "$release_count release(s) found matching $discid\n"; 
     54        for my $release (@releases) { 
     55            warn sprintf "%2d) $base%s %s %s (%s)\n",  
    4756            $i++, 
    4857            $xpath->findvalue('@id', $release)->value, 
     
    5059            $xpath->findvalue('.//label-info/catalog-number', $release)->value, 
    5160            $xpath->findvalue('barcode', $release)->value; 
     61        } 
     62 
     63        my $selection = 0; 
     64 
     65        while ($selection < 1 || $selection > $release_count) { 
     66            print STDERR "Select a release (1-$release_count): "; 
     67            $selection = <STDIN>; 
     68            chomp $selection; 
     69            return if $selection =~ /^q/i; 
     70        } 
     71 
     72        return $releases[$selection - 1]; 
    5273    } 
    53  
    54     my $selection = 0; 
    55  
    56     while ($selection < 1 || $selection > $release_count) { 
    57         print STDERR "Select a release (1-$release_count): "; 
    58         $selection = <STDIN>; 
    59         chomp $selection; 
    60         return if $selection =~ /^q/i; 
    61     } 
    62  
    63     return $releases[$selection - 1]; 
    6474} 
    6575 
    6676sub get_musicbrainz_info { 
    67     my ($discid) = @_; 
     77    my $params = shift; 
     78 
     79    my $discid = $params->{discid}; 
    6880    my %info; 
    6981 
     
    7890 
    7991    #my $release = $releases[0]; 
    80     my $release = select_release($xpath, $discid); 
     92    my $release = select_release($xpath, $params); 
    8193    return unless $release; 
    8294 
Note: See TracChangeset for help on using the changeset viewer.