From 2cf6210e1a84cefb3b3c95e21fe5bba0a148f9c0 Mon Sep 17 00:00:00 2001 From: Raphael Henrique Date: Sat, 6 Mar 2021 23:36:27 -0300 Subject: [PATCH] set default values of 'duration', 'max_duration' and 'file_duration' to 0 if it is nil for avoid errors when performing arithmetic operations --- src/thumbnailer_server.lua | 3 ++- src/thumbnailer_shared.lua | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/thumbnailer_server.lua b/src/thumbnailer_server.lua index c417b29..1703cfd 100644 --- a/src/thumbnailer_server.lua +++ b/src/thumbnailer_server.lua @@ -146,6 +146,7 @@ function do_worker_job(state_json_string, frames_json_string) end local file_duration = mp.get_property_native("duration") + if file_duration == nil then file_duration = 0 end local file_path = thumb_state.worker_input_path if thumb_state.is_remote then @@ -270,4 +271,4 @@ register_timer = mp.add_periodic_timer(0.1, register_function) mp.register_script_message("mpv_thumbnail_script-slaved", function() msg.debug("Successfully registered with master") register_timer:stop() -end) \ No newline at end of file +end) diff --git a/src/thumbnailer_shared.lua b/src/thumbnailer_shared.lua index b0e5dfd..f1c28a4 100644 --- a/src/thumbnailer_shared.lua +++ b/src/thumbnailer_shared.lua @@ -165,6 +165,7 @@ end function Thumbnailer:get_delta() local file_path = mp.get_property_native("path") local file_duration = mp.get_property_native("duration") + if file_duration == nil then file_duration = 0 end local is_seekable = mp.get_property_native("seekable") -- Naive url check @@ -202,6 +203,7 @@ function Thumbnailer:get_thumbnail_count(delta) return 0 end local file_duration = mp.get_property_native("duration") + if file_duration == nil then file_duration = 0 end return math.ceil(file_duration / delta) end @@ -278,7 +280,9 @@ function Thumbnailer:register_client() -- This will be executed after the on_video_change (because it's registered after it) mp.observe_property("video-dec-params", "native", function() local duration = mp.get_property_native("duration") + if duration == nil then duration = 0 end local max_duration = thumbnailer_options.autogenerate_max_duration + if max_duration == nil then max_duration = 0 end if duration ~= nil and self.state.available and thumbnailer_options.autogenerate then -- Notify if autogenerate is on and video is not too long