- Timestamp:
- 07/02/15 15:41:41 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/MusicBrainz.pm
r40 r43 32 32 } 33 33 34 sub interactive_select_release { 35 my ($xpath, $release_count, $discid, @releases) = @_; 36 my $base = 'http://musicbrainz.org/release/'; 37 38 my $i = 1; 39 # present the user with an interactive menu to pick/confirm the correct release ID 40 warn "$release_count release(s) found matching $discid\n"; 41 for my $release (@releases) { 42 warn sprintf "%2d) $base%s %s %s (%s)\n", 43 $i++, 44 $xpath->findvalue('@id', $release)->value, 45 $xpath->findvalue('.//label-info/label/name', $release)->value, 46 $xpath->findvalue('.//label-info/catalog-number', $release)->value, 47 $xpath->findvalue('barcode', $release)->value; 48 } 49 50 my $selection = 0; 51 52 while ($selection < 1 || $selection > $release_count) { 53 print STDERR "Select a release (1-$release_count): "; 54 $selection = <STDIN>; 55 chomp $selection; 56 return if $selection =~ /^q/i; 57 } 58 59 return $releases[$selection - 1]; 60 } 61 34 62 sub select_release { 35 63 my ($xpath, $params) = @_; … … 41 69 # try to pick the release automatically by the barcode 42 70 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; 71 if (@releases > 1) { 72 warn "Found more than one release with discid $discid and barcode $barcode\n"; 73 return interactive_select_release($xpath, scalar @releases, $discid, @releases); 74 } elsif (!@releases) { 75 warn "Found no releases with discid $discid and barcode $barcode\n"; 76 return; 77 } 45 78 return $releases[0]; 46 79 } else { 47 80 my $release_count = $xpath->findvalue('count(//release)'); 48 81 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", 56 $i++, 57 $xpath->findvalue('@id', $release)->value, 58 $xpath->findvalue('.//label-info/label/name', $release)->value, 59 $xpath->findvalue('.//label-info/catalog-number', $release)->value, 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]; 82 return interactive_select_release($xpath, $release_count, $discid, @releases); 73 83 } 74 84 }
Note: See TracChangeset
for help on using the changeset viewer.