-
Notifications
You must be signed in to change notification settings - Fork 0
/
Subtitle_Track_Selection.lua
80 lines (67 loc) · 1.66 KB
/
Subtitle_Track_Selection.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
-------------- Subtitle Track Selection --------------
local External = true --Toggle external subtitle
--script-message-to Subtitle_Track_Selection toggleExternal false
--or
--script-message toggleExternal true
function toggleExternal(value)
if value == "true" then
External = true
else
External = false
end
end
mp.register_script_message("toggleExternal", toggleExternal)
local function select_sub()
local track_list = mp.get_property_native("track-list")
local selected_sid = ""
for _, sub in ipairs(track_list) do
if sub.type == "sub" then
if sub.forced and sub.default then
selected_sid = sub.id
break
end
end
end
if selected_sid == "" then
for _, sub in ipairs(track_list) do
if sub.type == "sub" then
if sub.forced and not sub.default then
selected_sid = sub.id
break
end
end
end
end
if selected_sid == "" then
for _, sub in ipairs(track_list) do
if sub.type == "sub" then
if sub.default and not sub.forced then
selected_sid = sub.id
break
end
end
end
end
if selected_sid == "" and External then
for _, sub in ipairs(track_list) do
if sub.type == "sub" then
if sub.external then
selected_sid = sub.id
break
end
end
end
end
if selected_sid == "" then
for _, sub in ipairs(track_list) do
if sub.type == "sub" then
selected_sid = "no"
break
end
end
end
if selected_sid ~= "" then
mp.set_property("sid", selected_sid)
end
end
mp.register_event("file-loaded", select_sub)