- # Create an album menu.
- my @playlist = ();
- my $entry;
-
- $menu = "MenuMPDAlbum" unless defined $menu;
-
- $album =~ s/"/\\"/g;
- print $sock "playlistfind album \"$album\"\n";
- while (<$sock>) {
- last if (/^OK/);
- die($_) if (/^ACK/);
-
- if (/^(\w+): (.*)$/) {
- if ($1 eq "file") {
- if (keys(%$entry) > 0) {
- addalbumentry(\@playlist, $entry)
- }
-
- $entry = {};
+ my $matches = get_tracks_by_release_mbid($albumid);
+ my @notqueued = ();
+
+ $menu //= "MenuMPDAlbum";
+
+ my $track_max = max(map { $_->{Track} } values %$matches);
+ my $disc_max = max(map { $_->{Disc} } values %$matches);
+
+ # CDs have a max of 99 tracks and I hope 100+-disc-releases
+ # don't exist so this is fine.
+ my $track_digits = $track_max >= 10 ? 2 : 1;
+ my $disc_digits = $disc_max > 1 ? $disc_max >= 10 ? 2 : 1 : 0;
+ my $currentdisc;
+
+ fvwm_cmd("AddToMenu", $menu);
+ fvwm_cmd("+", "Release not found", "Title") unless keys %$matches;
+ foreach my $file (sort { albumsort($matches, $a, $b) } keys %$matches) {
+ my $entry = $matches->{$file};
+
+ # Format disc/track numbers
+ $entry->{trackfmt} = sprintf("%*.*s%.*s%*d\t",
+ $disc_digits, $disc_digits, $entry->{Disc},
+ $disc_digits, "-",
+ $track_digits, $entry->{Track});
+ $entry->{trackfmt} =~ s/ /\N{U+2007}/g;
+
+ unless (exists $entry->{Id}) {
+ my ($id) = get_ids_by_filename($file);
+ if (defined $id) {
+ $entry->{Id} = $id;
+ } else {
+ push @notqueued, $entry;
+ next;