-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPVShow.lua
171 lines (156 loc) · 5.09 KB
/
MPVShow.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
--filename
fname = mp.get_property_native("playlist")[1]["filename"]
--There is a small quirk in the internal slide counter,
--effectively slide 1 always starts at 0 and ends at 0.
--what user would call slide 1 is just internally counted as slide 2.
slide = 1
local function mysplit(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
local function read_file()
print(fname..".slinfo")
dir =mp.get_property_native("working-directory")
print(dir.."/"..fname..".slinfo")
local file = io.open(dir .. "/" .. fname .. ".slinfo" , "r")
if file==nil then
print("slinfo file not found")
return {{}}
end
local content = file:read "*a" -- *a or *all reads the whole file
file:close()
local retval = {}
linesplits = mysplit(content,'\n')
for i,ent in ipairs(linesplits) do
table.insert(retval,mysplit(ent))
--ll = mysplit(ent)
--retval[tonumber(ll[1])] = ll[2]
end
return retval
end
slidedat = read_file(fname);
slide_t = tonumber(slidedat[slide][1])
slide_l = slidedat[slide][2]
function getslideno(t)
for i,v in ipairs(slidedat) do
if tonumber(v[1]) > tonumber(t) then
return i
end
end
end
function seekend()
mp.command("seek " .. slidedat[slide][1] .. " absolute")
mp.set_property_native("pause",false)
end
function seekprev()
if slide==2 then
mp.command("seek " .. slidedat[1][1] .. " absolute")
mp.set_property_native("pause",false)
elseif slide==1 then
mp.command("seek " .. 0 .. " absolute")
mp.set_property_native("pause",false)
else
mp.command("seek " .. slidedat[slide-2][1] .. " absolute")
mp.set_property_native("pause",false)
end
end
function pause_on_slide(name,value)
--print(value)
--if slidedat[tonumber(value)] > "noloop" then
--end
if value==nil then
return nil
else
--print(value)
end
--next_slide_t = tonumber(slidedat[next_slide][1])
if value >= tonumber(slidedat[slide][1]) then
--mp.command("seek " .. slidedat[slide][1] .. " absolute")
mp.set_property_native("pause",true)
if slide_l ~= nil then
mp.set_property_native("ab-loop-a",tonumber(slidedat[slide-1][1]))
mp.set_property_native("ab-loop-b",tonumber(slidedat[slide][1]))
mp.set_property_native("pause",false)
else
mp.set_property_native("ab-loop-a","no")
mp.set_property_native("ab-loop-b","no")
end
inc_slide(1)
print("slide is now",slide)
--mp.command("seek " .. next_slide_t .. " absolute")
end
end
function nextslide()
mp.unobserve_property(pause_on_slide)
seekend()
inc_slide(1)
print("slide is now",slide)
--we really dont check if the word is "loop" just that its
--not a whitespace after timestamp, but user needn't know ;)
if slide_l ~=nil then
mp.set_property_native("ab-loop-a",tonumber(slidedat[slide-1][1]))
mp.set_property_native("ab-loop-b",tonumber(slidedat[slide][1]))
mp.set_property_native("pause",false)
else
mp.set_property_native("ab-loop-a","no")
mp.set_property_native("ab-loop-b","no")
mp.set_property_native("pause",false)
end
mp.observe_property("time-pos","native",pause_on_slide)
end
function prevslide()
mp.unobserve_property(pause_on_slide)
seekprev()
inc_slide(-1)
print("slide is now",slide)
if slide_l ~=nil then
mp.set_property_native("ab-loop-a",tonumber(slidedat[slide-1][1]))
mp.set_property_native("ab-loop-b",tonumber(slidedat[slide][1]))
mp.set_property_native("pause",false)
else
mp.set_property_native("ab-loop-a","no")
mp.set_property_native("ab-loop-b","no")
mp.set_property_native("pause",false)
end
mp.observe_property("time-pos","native",pause_on_slide)
end
function inc_slide(n)
slide=slide+n
if slide<1 then
slide=1
end
if slidedat[slide] == nil then
return
elseif slidedat[slide][1] == "end" then
print("set end ",slide_t)
slidedat[slide][1] = tonumber(mp.get_property("duration"))
slide_t = tonumber(mp.get_property("duration"))
slide_l = slidedat[slide][2]
else
slide_t = tonumber(slidedat[slide][1])
slide_l = slidedat[slide][2]
end
end
function unpause()
mp.set_property_native("ab-loop-a","no")
mp.set_property_native("ab-loop-b","no")
mp.set_property_native("pause",false)
end
curdir = mp.get_property_native("working-directory")
slinfofile = io.open(curdir.."/"..fname..".slinfo", "r") -- r read mode and b binary mode
if slinfofile==nil then
print("Couldnt find .slinfo file, playing like usual video")
else
mp.observe_property("time-pos","native",pause_on_slide)
mp.add_key_binding("n",nextslide)
mp.add_key_binding("b",prevslide)
mp.remove_key_binding("m")
mp.add_forced_key_binding("m",unpause)
print("done")
end