From 091d929a6add23feea0cc7ae1ece1406dd80a6cd Mon Sep 17 00:00:00 2001 From: Anurup Dey Date: Sat, 5 Feb 2022 16:13:45 +0530 Subject: [PATCH 1/5] Corrected Location for script. As per the `mpv` manpage, the correct path for scripts is in `~/.config/mpv/scripts/` and not `~/.config/scripts/` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a8bd46a..055458b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Install mpv, lua, ffmpeg, libnotify and ImageMagick packages Installation ------------ -Just drop `notify.lua` into the folder `~/.config/scripts/lua` (create it when neccessary), +Just drop `notify.lua` into the folder `~/.config/mpv/scripts/` (create it when neccessary), and mpv will find it. Optionally, you can add it to mpv's command line: mpv --lua=/path/to/notify.lua From b2016cd4a556fe380713d7c8549a3531fddc0247 Mon Sep 17 00:00:00 2001 From: Anurup Dey Date: Sat, 5 Feb 2022 18:21:00 +0530 Subject: [PATCH 2/5] Add Default icon if Album art is missing --- notify.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/notify.lua b/notify.lua index 98cbcf1..9c3d6f8 100644 --- a/notify.lua +++ b/notify.lua @@ -64,6 +64,12 @@ function string.safe_filename(str) return s; end +-- check if a file exists and is readable +function file_exists(name) + local f=io.open(name, "r") + if f~=nil then io.close(f) return true else return false end +end + ------------------------------------------------------------------------------- -- here we go. ------------------------------------------------------------------------------- @@ -127,16 +133,19 @@ function notify_current_track() -- print_debug("title: " .. title) -- absolute filename of currently playing audio file - local abs_filename = os.getenv("PWD") .. "/" .. mp.get_property_native("path") + -- local abs_filename = os.getenv("PWD") .. "/" .. mp.get_property_native("path") + local abs_filename = mp.get_property_native("path") -- print_debug(abs_filename) params = "" -- extract cover art: set it as icon in notification params if extracted_image_from_audiofile(abs_filename, COVER_ART_PATH) then - if scaled_image(COVER_ART_PATH, ICON_PATH) then + if file_exists(COVER_ART_PATH) and scaled_image(COVER_ART_PATH, ICON_PATH) then params = "-i " .. ICON_PATH + else + params = "-i 'audio-x-generic'" end - end + end -- form notification summary summary_str ="Now playing:" From 8c8aaff649d324020d6c92f383cf84c07b496290 Mon Sep 17 00:00:00 2001 From: Anurup Dey Date: Sun, 6 Feb 2022 15:09:16 +0530 Subject: [PATCH 3/5] Add notification of unpause --- notify.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/notify.lua b/notify.lua index 9c3d6f8..29830da 100644 --- a/notify.lua +++ b/notify.lua @@ -166,19 +166,21 @@ function notify_current_track() body = string.shellescape(body_str) - local command = ("notify-send -a mpv %s -- %s %s"):format(params, summary, body) + local command = ("notify-send -a mpv -t 5000 %s -- %s %s"):format(params, summary, body) -- print_debug("command: " .. command) os.execute(command) end -function notify_metadata_updated(name, data) - notify_current_track() +function notify_pause_updated(name, value) + if value == false then + notify_current_track() + end end -- insert main() here mp.register_event("file-loaded", notify_current_track) --- mp.observe_property("metadata", nil, notify_metadata_updated) +mp.observe_property("pause", "bool", notify_pause_updated) From 239e7d7255f11f860d303aa8f53a7311bb84df45 Mon Sep 17 00:00:00 2001 From: Anurup Dey Date: Sat, 12 Feb 2022 16:18:32 +0530 Subject: [PATCH 4/5] Add notification on pause --- notify.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/notify.lua b/notify.lua index 29830da..bd629c4 100644 --- a/notify.lua +++ b/notify.lua @@ -176,6 +176,9 @@ end function notify_pause_updated(name, value) if value == false then notify_current_track() + else + local command = "notify-send -a mpv -t 5000 -i audio-x-generic -- \"Music Paused\"" + os.execute(command) end end From 9f0910b8d6a2523848a43726e2c9e590f954b512 Mon Sep 17 00:00:00 2001 From: Anurup Dey Date: Sat, 12 Feb 2022 16:34:47 +0530 Subject: [PATCH 5/5] Make the plugin work with both absolute and relative path --- notify.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/notify.lua b/notify.lua index bd629c4..ad5b6d7 100644 --- a/notify.lua +++ b/notify.lua @@ -111,6 +111,7 @@ end COVER_ART_PATH = "/tmp/covert_art.jpg" ICON_PATH = "/tmp/icon.jpg" + function notify_current_track() os.remove(COVER_ART_PATH) os.remove(ICON_PATH) @@ -133,9 +134,10 @@ function notify_current_track() -- print_debug("title: " .. title) -- absolute filename of currently playing audio file - -- local abs_filename = os.getenv("PWD") .. "/" .. mp.get_property_native("path") local abs_filename = mp.get_property_native("path") - -- print_debug(abs_filename) + if not abs_filename:match("^%/") then + abs_filename = os.getenv("PWD") .. "/" .. abs_filename + end params = "" -- extract cover art: set it as icon in notification params