From 01a5fd2b8619c71d2acdf38b30de9f37e853d1d7 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sat, 16 Mar 2024 22:23:38 +0100 Subject: filter subtitles before copy in mpv --- .config/mpv/scripts/copy-subs.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to '.config/mpv') diff --git a/.config/mpv/scripts/copy-subs.lua b/.config/mpv/scripts/copy-subs.lua index 32ae7ef..305299a 100644 --- a/.config/mpv/scripts/copy-subs.lua +++ b/.config/mpv/scripts/copy-subs.lua @@ -3,7 +3,13 @@ _G.auto = false function copy() local sub = mp.get_property("sub-text") if sub then - os.execute("echo '" .. sub:gsub('\'', '\'\\\'\'') .. "' | xclip -selection clipboard -i") + -- remove some specific unicode characters + sub = sub:gsub('\u{27a1}', '') + sub = sub:gsub('\u{fffd}', '') + + sub = sub:gsub('\n', ' ') -- replace newlines with space + sub = sub:gsub('\'', '\'\\\'\'') -- escape single quotes + os.execute("echo '" .. sub .. "' | xclip -selection clipboard -i") end end -- cgit v1.2.3