- Timestamp:
- 05/08/15 14:48:29 (10 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/DiscFlacFile.pm
r32 r40 36 36 sub discid { 37 37 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 41 sub barcode { 42 my $self = shift; 43 return $self->flac->tags('BARCODE'); 39 44 } 40 45 -
trunk/lib/MusicBrainz.pm
r31 r40 33 33 34 34 sub select_release { 35 my ($xpath, $ discid) = @_;35 my ($xpath, $params) = @_; 36 36 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}; 41 39 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", 47 56 $i++, 48 57 $xpath->findvalue('@id', $release)->value, … … 50 59 $xpath->findvalue('.//label-info/catalog-number', $release)->value, 51 60 $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]; 52 73 } 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];64 74 } 65 75 66 76 sub get_musicbrainz_info { 67 my ($discid) = @_; 77 my $params = shift; 78 79 my $discid = $params->{discid}; 68 80 my %info; 69 81 … … 78 90 79 91 #my $release = $releases[0]; 80 my $release = select_release($xpath, $ discid);92 my $release = select_release($xpath, $params); 81 93 return unless $release; 82 94 -
trunk/mbz
r31 r40 12 12 13 13 GetOptions( 14 'flac=s' =>\my $FLAC_FILE, 14 'flac=s' => \my $FLAC_FILE, 15 'barcode=s' => \my $BARCODE, 15 16 'get-release-id' => \my $GET_RELEASE_ID, 16 'xml' =>\my $GET_XML,17 'xml' => \my $GET_XML, 17 18 ); 18 19 19 20 my $discid; 21 my $barcode; 20 22 21 23 if ($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; 23 27 } else { 24 $discid = shift; 28 $discid = shift; 29 $barcode = $BARCODE; 25 30 } 26 31 … … 35 40 36 41 # otherwise, do the full parsing of the data 37 my $info = get_musicbrainz_info($discid); 42 my $info = get_musicbrainz_info({ 43 discid => $discid, 44 barcode => $barcode, 45 }); 38 46 39 47 exit unless $info;
Note: See TracChangeset
for help on using the changeset viewer.