Last active
January 31, 2023 04:14
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
Author
cirrusUK
commented
Jan 31, 2023
via email
See manpage of dunst, notify-send or whichever notification daemon you use.
Regards
…On Sun, 29 Jan 2023, 15:59 Ahloi, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hello, thanks for the script, it work flawless.
how do i change the duration when the notification start? i mean now it
notify me a few second after the video played, which is quite slow.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/a995da28f4a48806e26fe0a85f7d0ab5#gistcomment-4452471>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOH33LF52Q75JBZF5LYCDDWU2HV3BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTAOBWGM3DIMBYU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment