-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.lua
89 lines (76 loc) · 2.48 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
--[[
mpv-open-imdb-page | https://github.com/ctlaltdefeat/mpv-open-imdb-page
This mpv script opens the IMDb page that corresponds to the currently playing media file,
whether a film or a specific TV episode.
This script requires open-imdb-page.py to be in the same directory.
The directory should be placed inside the script folder of mpv's configuration.
Requires Python 3 and the following pip packages:
guessit
cinemagoer
Assigns the script-binding launch-imdb as Ctrl+i
]]
function get_python_binary()
local msg = ""
-- try: python
local python_version = mp.command_native({
name = "subprocess",
args = { "python", "--version"},
capture_stdout = true
})
if python_version.error_string ~= "" then
msg = msg.."'python' not found; "
else
if python_version.stdout:find("3%.") ~= nil then
msg = msg.."'python' with version 3 found!"
return "python", msg
else
msg = msg.."'python' is not version 3; "
end
end
-- try: python3
python_version = mp.command_native({
name = "subprocess",
args = { "python3", "--version" },
capture_stdout = true
})
if python_version.error_string ~= "" then
msg = msg.."'python3' not found; "
else
msg = msg.."'python3' found!"
return "python3", msg
end
--no python 3 found
msg = msg.."no Python 3 binary found!"
return nil, msg
end
function callback(success, result, error)
if result.status == 0 then
mp.osd_message("Launched browser", 1)
else
mp.osd_message("Unable to find IMDb URL", 3)
end
end
function launch_imdb()
local python_binary, python_msg = get_python_binary()
if python_binary ~= nil then
mp.msg.info(python_msg)
mp.msg.info("Calling open-imdb-page.py")
mp.osd_message("Searching IMDb...", 30)
local cmd = mp.command_native_async({
name = "subprocess",
args = {
python_binary,
mp.get_script_directory().."/open-imdb-page.py",
mp.get_property("filename")
}
},
callback
)
else
mp.msg.error(python_msg)
mp.osd_message("ERROR: "..python_msg, 10)
return
end
end
-- change key binding as desired
mp.add_key_binding('ctrl+i', 'open-imdb-page', launch_imdb)