my $SELF = "$FindBin::Bin/$FindBin::Script";
my $MUSIC = $ENV{MUSIC} // "/srv/music";
-my $sock;
+my ($sock, $mpd_have_binarylimit);
my ($albumid, $albumname, $trackid, $recordingid);
my ($topmenu, $menu);
$c = "%";
}
+ if ($mpd_have_binarylimit) {
+ # --embedded implies and requires binarylimit support
+ push @opts, "--embedded";
+ } else {
+ push @opts, "--no-binarylimit";
+ }
+
open THUMB, "-|", "$FindBin::Bin/mpdthumb.sh", @opts, "--", @_;
foreach (@_) {
my $thumb = <THUMB>;
@submenu);
}
+# 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 = "";
+ }
+}
+
# Given a work MBID, return a hash reference containing all tracks
# linked to that work. The hash keys are filenames.
sub get_tracks_by_work_mbid {
die("MPD version $MPD::major.$MPD::minor.$MPD::revision insufficient.")
unless MPD::min_version(MPD_MJR_MIN, MPD_MNR_MIN, MPD_REV_MIN);
+MPD::exec("binarylimit", 64);
+while (<$sock>) {
+ $mpd_have_binarylimit = 1 if /^OK/;
+ last if /^OK/ or /^ACK/;
+}
+
if ($mode eq "top") {
my %current;
my %state;
top_track_title(\%current);
top_track_artist(\%current);
top_track_album(\%current);
+ top_track_musicbrainz(\%current);
} else {
fvwm_cmd("AddToMenu", $menu, "[current track unavailable]");
}
$menu //= "MenuMPDRecordings";
my @tracks = sort { $a->{Title} cmp $b->{Title} }
grep { $_->{Album} eq $albumname } @recs;
+
+ # Show thumbnails for standalone recordings
+ my @thumbs = get_item_thumbnails({ small => 1 },
+ map { $_->{file} } @tracks);
+ foreach my $entry (@tracks) {
+ $entry->{thumb} = shift @thumbs;
+ }
+
my @notqueued = update_entry_ids(@tracks);
fvwm_cmd("AddToMenu", $menu);