- Timestamp:
- 05/08/15 14:48:29 (10 years ago)
- Location:
- trunk/lib
- Files:
-
- 2 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
Note: See TracChangeset
for help on using the changeset viewer.