+# Generate the "MusicBrainz:" entry in the top menu.
+sub top_track_musicbrainz {
+ my ($entry) = @_;
+ my ($track_mbid, $recording_mbid, $release_mbid);
+ my @artist_mbids;
+ my $label = "MB:";
+ my %idmap;
+
+ ($track_mbid) = get_track_metadata($entry, "MUSICBRAINZ_RELEASETRACKID");
+ ($recording_mbid) = get_track_metadata($entry, "MUSICBRAINZ_TRACKID");
+ ($release_mbid) = get_track_metadata($entry, "MUSICBRAINZ_ALBUMID");
+ @artist_mbids = get_track_metadata($entry, "MUSICBRAINZ_ARTISTID");
+ return unless $track_mbid // $recording_mbid
+ // $release_mbid // @artist_mbids;
+
+ foreach (get_track_metadata($entry, "Comment")) {
+ $idmap{$1} = $2 if /^([^=]*)=(.*) \(idmap\)$/;
+ }
+
+ fvwm_cmd("AddToMenu", $menu, "", "Nop");
+ if ($track_mbid) {
+ fvwm_cmd("AddToMenu", $menu, "$label\tShow track",
+ "Exec", "exec", "xdg-open",
+ "https://musicbrainz.org/track/$track_mbid");
+ $label = "";
+ } elsif ($recording_mbid) {
+ fvwm_cmd("AddToMenu", $menu, "$label\tShow recording",
+ "Exec", "exec", "xdg-open",
+ "https://musicbrainz.org/recording/$recording_mbid");
+ $label = "";
+ } elsif ($release_mbid) {
+ fvwm_cmd("AddToMenu", $menu, "$label\tShow",
+ "Exec", "exec", "xdg-open",
+ "https://musicbrainz.org/release/$release_mbid");
+ $label = "";
+ }
+
+ foreach my $mbid (@artist_mbids) {
+ my $name = " $idmap{$mbid}" if $idmap{$mbid};
+
+ fvwm_cmd("AddToMenu", $menu, "$label\tShow artist$name",
+ "Exec", "exec", "xdg-open",
+ "https://musicbrainz.org/artist/$mbid");
+ $label = "";
+ }
+}
+