Skip to content

Commit 967a572

Browse files
author
blank_name
committed
Guard against nil properties.
1 parent 682becf commit 967a572

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/thumbnailer_server.lua

+9-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function create_thumbnail_mpv(file_path, timestamp, size, output_path, options)
1313
or thumbnailer_options.remote_direct_stream)
1414

1515
local header_fields_arg = nil
16-
local header_fields = mp.get_property_native("http-header-fields")
16+
local header_fields = mp.get_property_native("http-header-fields", {})
1717
if #header_fields > 0 then
1818
-- We can't escape the headers, mpv won't parse "--http-header-fields='Name: value'" properly
1919
header_fields_arg = "--http-header-fields=" .. table.concat(header_fields, ",")
@@ -36,8 +36,8 @@ function create_thumbnail_mpv(file_path, timestamp, size, output_path, options)
3636
-- Pass HTTP headers from current instance
3737
header_fields_arg,
3838
-- Pass User-Agent and Referer - should do no harm even with ytdl active
39-
"--user-agent=" .. mp.get_property_native("user-agent"),
40-
"--referrer=" .. mp.get_property_native("referrer"),
39+
"--user-agent=" .. mp.get_property_native("user-agent", ""),
40+
"--referrer=" .. mp.get_property_native("referrer", ""),
4141
-- Disable hardware decoding
4242
"--hwdec=no",
4343

@@ -146,6 +146,11 @@ function do_worker_job(state_json_string, frames_json_string)
146146
end
147147

148148
local file_duration = mp.get_property_native("duration")
149+
-- Bail if we get a nil duration
150+
if not file_duration then
151+
return
152+
end
153+
149154
local file_path = thumb_state.worker_input_path
150155

151156
if thumb_state.is_remote then
@@ -270,4 +275,4 @@ register_timer = mp.add_periodic_timer(0.1, register_function)
270275
mp.register_script_message("mpv_thumbnail_script-slaved", function()
271276
msg.debug("Successfully registered with master")
272277
register_timer:stop()
273-
end)
278+
end)

src/thumbnailer_shared.lua

+10-10
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ function Thumbnailer:update_state()
9393

9494
self.state.ready = true
9595

96-
local file_path = mp.get_property_native("path")
96+
local file_path = mp.get_property_native("path", "")
9797
self.state.is_remote = file_path:find("://") ~= nil
9898

9999
self.state.available = false
100100

101101
-- Make sure the file has video (and not just albumart)
102-
local track_list = mp.get_property_native("track-list")
102+
local track_list = mp.get_property_native("track-list", {})
103103
local has_video = false
104104
for i, track in pairs(track_list) do
105105
if track.type == "video" and not track.external and not track.albumart then
@@ -118,10 +118,10 @@ end
118118

119119

120120
function Thumbnailer:get_thumbnail_template()
121-
local file_path = mp.get_property_native("path")
121+
local file_path = mp.get_property_native("path", "")
122122
local is_remote = file_path:find("://") ~= nil
123123

124-
local filename = mp.get_property_native("filename/no-ext")
124+
local filename = mp.get_property_native("filename/no-ext", "")
125125
local filesize = mp.get_property_native("file-size", 0)
126126

127127
if is_remote then
@@ -143,7 +143,7 @@ end
143143

144144

145145
function Thumbnailer:get_thumbnail_size()
146-
local video_dec_params = mp.get_property_native("video-dec-params")
146+
local video_dec_params = mp.get_property_native("video-dec-params", {})
147147
local video_width = video_dec_params.dw
148148
local video_height = video_dec_params.dh
149149
if not (video_width and video_height) then
@@ -163,7 +163,7 @@ end
163163

164164

165165
function Thumbnailer:get_delta()
166-
local file_path = mp.get_property_native("path")
166+
local file_path = mp.get_property_native("path", "")
167167
local file_duration = mp.get_property_native("duration")
168168
local is_seekable = mp.get_property_native("seekable")
169169

@@ -201,8 +201,8 @@ function Thumbnailer:get_thumbnail_count(delta)
201201
if delta == nil then
202202
return 0
203203
end
204-
local file_duration = mp.get_property_native("duration")
205204

205+
local file_duration = mp.get_property_native("duration", 0)
206206
return math.ceil(file_duration / delta)
207207
end
208208

@@ -320,13 +320,13 @@ function Thumbnailer:_create_thumbnail_job_order()
320320
end
321321

322322
function Thumbnailer:prepare_source_path()
323-
local file_path = mp.get_property_native("path")
323+
local file_path = mp.get_property_native("path", "")
324324

325325
if self.state.is_remote and thumbnailer_options.remote_direct_stream then
326326
-- Use the direct stream (possibly) provided by ytdl
327327
-- This skips ytdl on the sub-calls, making the thumbnailing faster
328328
-- Works well on YouTube, rest not really tested
329-
file_path = mp.get_property_native("stream-path")
329+
file_path = mp.get_property_native("stream-path", "")
330330

331331
-- edl:// urls can get LONG. In which case, save the path (URL)
332332
-- to a temporary file and use that instead.
@@ -336,7 +336,7 @@ function Thumbnailer:prepare_source_path()
336336
-- Path is too long for a playlist - just pass the original URL to
337337
-- workers and allow ytdl
338338
self.state.worker_extra.enable_ytdl = true
339-
file_path = mp.get_property_native("path")
339+
file_path = mp.get_property_native("path", "")
340340
msg.warn("Falling back to original URL and ytdl due to LONG source path. This will be slow.")
341341

342342
elseif #file_path > 1024 then

0 commit comments

Comments
 (0)