How to get subtitle word under mouse via lua scripting? #15907
-
Hi, I'm not a native English speaker and mostly will watch videos that come with subtitle if the video language is English. I was a PotPlayer user, which has a decent feature that allows user use the mouse to click on a word from the subtitle to preform a quick internet search of that word when the video is paused. I'd like to have similar feature in mpv, then I looked into the lua scripting documentation. To implement such feature, I need to do the following steps:
Sadly I didn't find any way to get the word under/at the mouse cursor. Did I missed something? Is there a way to implement such thing? Alternatively, is there any way to make the subtitle word selectable so I can manually copy the word to search them? Some other links might related while I do the resource:
Thanks in advanced! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
There's no way to get the position of words in the subtitle. At best you can use a script like this to select a word in a menu. You need git master for mouse support. local input = require 'mp.input'
mp.add_key_binding('F1', 'select-sub-word', function ()
local words = {}
for word in mp.get_property('sub-text', ''):gmatch('%g+') do
words[#words + 1] = word
end
if #words == 0 then
return
end
input.select({
prompt = 'Select a word:',
items = words,
submit = function (i)
mp.osd_message('Selected ' .. words[i])
-- Do something with the word.
end
})
end) |
Beta Was this translation helpful? Give feedback.
There's no way to get the position of words in the subtitle. At best you can use a script like this to select a word in a menu. You need git master for mouse support.