-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
clipshot.lua
60 lines (55 loc) · 1.82 KB
/
clipshot.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
---Screenshot the video and copy it to the clipboard
---@author ObserverOfTime
---@license 0BSD
---@class ClipshotOptions
---@field name string
---@field type string
local o = {
name = 'mpv-screenshot.jpeg',
type = '' -- defaults to jpeg
}
require('mp.options').read_options(o, 'clipshot')
local file, cmd
local platform = mp.get_property_native('platform')
if platform == 'windows' then
file = os.getenv('TEMP')..'\\'..o.name
cmd = {
'powershell', '-NoProfile', '-Command',
'Add-Type -Assembly System.Windows.Forms, System.Drawing;',
string.format(
"[Windows.Forms.Clipboard]::SetImage([Drawing.Image]::FromFile('%s'))",
file:gsub("'", "''")
)
}
elseif platform == 'darwin' then
file = os.getenv('TMPDIR')..'/'..o.name
-- png: «class PNGf»
local type = o.type ~= '' and o.type or 'JPEG picture'
cmd = {
'osascript', '-e', string.format(
'set the clipboard to (read (POSIX file %q) as %s)',
file, type
)
}
else
file = '/tmp/'..o.name
if os.getenv('XDG_SESSION_TYPE') == 'wayland' then
cmd = {'sh', '-c', ('wl-copy < %q'):format(file)}
else
local type = o.type ~= '' and o.type or 'image/jpeg'
cmd = {'xclip', '-sel', 'c', '-t', type, '-i', file}
end
end
---@param arg string
---@return fun()
local function clipshot(arg)
return function()
mp.commandv('screenshot-to-file', file, arg)
mp.command_native_async({'run', unpack(cmd)}, function(suc, _, err)
mp.osd_message(suc and 'Copied screenshot to clipboard' or err, 1)
end)
end
end
mp.add_key_binding('c', 'clipshot-subs', clipshot('subtitles'))
mp.add_key_binding('C', 'clipshot-video', clipshot('video'))
mp.add_key_binding('Alt+c', 'clipshot-window', clipshot('window'))