-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
58 lines (43 loc) · 1.44 KB
/
main.lua
File metadata and controls
58 lines (43 loc) · 1.44 KB
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
local mp = require('mp')
local function subprocess(args, stdin_data, detach)
return mp.command_native({
name = "subprocess",
playback_only = false,
args = args,
stdin_data = stdin_data,
-- If the streams are not _captured_ it will spam console log...
capture_stdout = true and (detach == nil or not detach),
capture_stderr = true and (detach == nil or not detach),
detach = detach,
})
end
if subprocess({"zbarimg", "--version"}).status ~= 0 then
mp.log("error", "zbarimg is not installed")
return
end
local function scan_image(callback)
return function()
local filename = os.tmpname()
mp.commandv("screenshot-to-file", filename)
local zbarimg = subprocess({"zbarimg", "-q", filename})
os.remove(filename)
if zbarimg.status ~= 0 then
mp.log("warn", "No valid qr code")
return
end
local qr_data = zbarimg.stdout:sub(string.len("QR-Code:") + 1, -2)
callback(qr_data)
end
end
if subprocess({"xclip", "-quiet", "-version"}).status == 0 then
mp.add_key_binding("ctrl+q", "copy-qr-code", scan_image(function(data)
subprocess({"xclip", "-selection", "clipboard"}, data, true)
-- subprocess({"/tmp/test.sh"}, data, true)
mp.osd_message("QR code copied to clipboard")
end))
end
if subprocess({"xdg-open", "--version"}).status == 0 then
mp.add_key_binding("ctrl+shift+q", "open-qr-code", scan_image(function(data)
subprocess({"xdg-open", data})
end))
end