Changeset 40 in flacrip


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
Location:
trunk
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/DiscFlacFile.pm

    r32 r40  
    3636sub discid { 
    3737    my $self = shift; 
    38     return $self->flac->info('MUSICBRAINZ_DISCID') || $self->tracks->discid; 
     38    return $self->flac->tags('MUSICBRAINZ_DISCID') || $self->tracks->discid; 
     39} 
     40 
     41sub barcode { 
     42    my $self = shift; 
     43    return $self->flac->tags('BARCODE'); 
    3944} 
    4045 
  • 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 
  • trunk/mbz

    r31 r40  
    1212 
    1313GetOptions( 
    14     'flac=s' =>\my $FLAC_FILE, 
     14    'flac=s'         => \my $FLAC_FILE, 
     15    'barcode=s'      => \my $BARCODE, 
    1516    'get-release-id' => \my $GET_RELEASE_ID, 
    16     'xml' =>\my $GET_XML, 
     17    'xml'            => \my $GET_XML, 
    1718); 
    1819 
    1920my $discid; 
     21my $barcode; 
    2022 
    2123if ($FLAC_FILE) { 
    22     $discid = DiscFlacFile->new({ file => $FLAC_FILE })->discid; 
     24    my $flac_disc = DiscFlacFile->new({ file => $FLAC_FILE }); 
     25    $discid  = $flac_disc->discid; 
     26    $barcode = $flac_disc->barcode; 
    2327} else { 
    24     $discid = shift; 
     28    $discid  = shift; 
     29    $barcode = $BARCODE; 
    2530} 
    2631 
     
    3540 
    3641# otherwise, do the full parsing of the data 
    37 my $info = get_musicbrainz_info($discid); 
     42my $info = get_musicbrainz_info({ 
     43    discid  => $discid, 
     44    barcode => $barcode, 
     45}); 
    3846 
    3947exit unless $info; 
Note: See TracChangeset for help on using the changeset viewer.