Skip to content

Instantly share code, notes, and snippets.

@cirrusUK
Last active January 31, 2023 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cirrusUK/a995da28f4a48806e26fe0a85f7d0ab5 to your computer and use it in GitHub Desktop.
Save cirrusUK/a995da28f4a48806e26fe0a85f7d0ab5 to your computer and use it in GitHub Desktop.
mpv now playing uses libnotify (dunst) and osd_cat notify.lua calls mpvnp,notifies on startup and file change. mpv_osd
#!/bin/bash
export DISPLAY=":0"
export XDG_RUNTIME_DIR=/run/user/$(id -u)
icon="/home/cirrus/.icons/play-4-48.png"
SERVICE="mpv"
MPVNP=$(ponymix list --short | awk -F '\t' '/sink-input/ && $4 == "mpv Media Player" {print $3}' ) ;
if pgrep -x "$SERVICE" >/dev/null ; then
sleep 3
dunstify -i "$icon" -r 100 "📺 MPV Now Playing " "$MPVNP" && echo -n "$MPVNP" | osd_cat -A left -p bottom -f '-*-envy code r-*-*-*-*-22-*-*-*-*-*-*-*' -o 40 -c '#00ff00' -s2
else
echo /dev/null 2>&1
fi
-- based on https://github.com/rohieb/mpv-notify
-- https://unix.stackexchange.com/a/455198/119298
lastcommand = nil
function string.shellescape(str)
return "'"..string.gsub(str, "'", "'\"'\"'").."'"
end
function do_notify(a,b)
-- local command = ("notify-send -a mpv -- %s %s %s"):format(a:shellescape(),
local command = ("/home/cirrus/.config/mpv/mpvnp"):format(b:shellescape())
if command ~= lastcommand then
os.execute(command)
lastcommand = command
end
end
function notify_current_track()
data = mp.get_property_native("metadata")
if data then
local artist = (data["ARTIST"] or data["artist"] or " ")
local title = (data["TITLE"] or data["title"] or " ")
if artist..title~=" " then
do_notify(artist, title)
return
end
end
local data = mp.get_property("path")
if data then
local file = data:gsub("^.-([^/]+)$","%1")
file = file:gsub("%....$","") -- delete 3 char suffix
local dir = data:gsub("^.-([^/]+)/[^/]*$","%1")
do_notify(dir, file)
end
end
mp.register_event("file-loaded", notify_current_track)
@cirrusUK
Copy link
Author

cirrusUK commented Jan 31, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment