select.lua: consider --sub-delay for the subtitle line selector

Preselect and seek to the correct subtitle line when there is a
sub-delay.

Also slightly increase the offset without a video track else it
occasionally doesn't seek to the selected line with non-0 sub-delay and
no video. This now uses the same offset as sub/sd.h.
This commit is contained in:
Guido Cella 2024-06-16 21:45:47 +02:00 committed by Dudemanguy
parent e3f496dbf5
commit 8873beabc3
1 changed files with 7 additions and 4 deletions

View File

@ -232,7 +232,8 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function ()
local sub_lines = {}
local sub_times = {}
local default_item
local time_pos = mp.get_property_native("time-pos")
local delay = mp.get_property_native("sub-delay")
local time_pos = mp.get_property_native("time-pos") - delay
local duration = mp.get_property_native("duration", math.huge)
-- Strip HTML and ASS tags.
@ -254,9 +255,11 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function ()
submit = function (index)
-- Add an offset to seek to the correct line while paused without a
-- video track.
local offset = mp.get_property_native("current-tracks/video/image") == false
and 0 or .09
mp.commandv("seek", sub_times[index] + offset, "absolute")
if mp.get_property_native("current-tracks/video/image") ~= false then
delay = delay + 0.1
end
mp.commandv("seek", sub_times[index] + delay, "absolute")
end,
})
end)