-
Notifications
You must be signed in to change notification settings - Fork 0
/
yomichampv.lua
66 lines (55 loc) · 1.91 KB
/
yomichampv.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- v. 0.2
-- Push subtitles to clipboard
-- in linux needs xsel or xclip to work
--
-- default keybinding to start/stop: Y
-- verify which command to use (false if none is found)
local clipboard = package.config:sub(1,1) == '\\' and 'clip.exe' or -- Windows
(pcall(function () io.popen('pbcopy'):close() end)) and 'pbcopy' or -- MacOS
os.execute('xsel -h > /dev/null 2>&1') and 'xsel -z -b' or -- xsel
os.execute('xclip -h > /dev/null 2>&1') and 'xclip -i -selection clipboard' -- xclip
local running
local function toclipboard(name, value)
if running and type(value) == 'string' then
io.popen(clipboard, 'w'):write(value):close()
end
end
local function stop()
running = false
mp.msg.warn('Quitting Yomichampv ...')
mp.unregister_event('end-file', stop)
mp.unobserve_property('sub-text', 'string', toclipboard)
mp.remove_key_binding('Yomichampv-pause')
mp.remove_key_binding('Yomichampv-resume')
end
-- get_active_subtrack from huglovefan/mpv-subside.lua
local function get_active_subtrack ()
local l = mp.get_property_native('track-list')
for _, t in ipairs(l) do
if t.type == 'sub' and t.selected then
return t.lang
end
end
return 'no'
end
local function start_stop()
if running then
stop()
mp.command('show-text "Quitting Yomichampv..."')
else
if get_active_subtrack() ~= 'ja' then
mp.command('show-text "Select japanese subtitles before' ..
' starting Yomichampv."')
else
running = true
mp.register_event('end-file', stop)
mp.observe_property('sub-text', 'string', toclipboard)
mp.add_forced_key_binding('mouse_leave', 'Yomichampv-pause',
function () mp.set_property_native('pause', true) end)
mp.add_forced_key_binding('mouse_move', 'Yomichampv-resume',
function () mp.set_property_native('pause', false) end)
mp.command('show-text "Starting Yomichampv..."')
end
end
end
mp.add_key_binding('y', 'start-stop-Yomichampv', start_stop)