mirror of https://github.com/mpv-player/mpv
select.lua: hide the hour when it's 0
Omit the hour in the chapter and subtitle line selectors when the file is shorter than an hour.
This commit is contained in:
parent
8939bfc3ef
commit
5657cd65b7
|
@ -149,13 +149,17 @@ mp.add_forced_key_binding(nil, "select-vid", function ()
|
||||||
"No available video tracks.")
|
"No available video tracks.")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function format_time(t)
|
local function format_time(t, duration)
|
||||||
local h = math.floor(t / (60 * 60))
|
local h = math.floor(t / (60 * 60))
|
||||||
t = t - (h * 60 * 60)
|
t = t - (h * 60 * 60)
|
||||||
local m = math.floor(t / 60)
|
local m = math.floor(t / 60)
|
||||||
local s = t - (m * 60)
|
local s = t - (m * 60)
|
||||||
|
|
||||||
return string.format("%.2d:%.2d:%.2d", h, m, s)
|
if duration >= 60 * 60 or h > 0 then
|
||||||
|
return string.format("%.2d:%.2d:%.2d", h, m, s)
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format("%.2d:%.2d", m, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
mp.add_forced_key_binding(nil, "select-chapter", function ()
|
mp.add_forced_key_binding(nil, "select-chapter", function ()
|
||||||
|
@ -167,8 +171,10 @@ mp.add_forced_key_binding(nil, "select-chapter", function ()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local duration = mp.get_property_native("duration", math.huge)
|
||||||
|
|
||||||
for i, chapter in ipairs(mp.get_property_native("chapter-list")) do
|
for i, chapter in ipairs(mp.get_property_native("chapter-list")) do
|
||||||
chapters[i] = format_time(chapter.time) .. " " .. chapter.title
|
chapters[i] = format_time(chapter.time, duration) .. " " .. chapter.title
|
||||||
end
|
end
|
||||||
|
|
||||||
input.select({
|
input.select({
|
||||||
|
@ -213,13 +219,14 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function ()
|
||||||
local default_item
|
local default_item
|
||||||
local sub_start = mp.get_property_native("sub-start",
|
local sub_start = mp.get_property_native("sub-start",
|
||||||
mp.get_property_native("time-pos"))
|
mp.get_property_native("time-pos"))
|
||||||
|
local duration = mp.get_property_native("duration", math.huge)
|
||||||
|
|
||||||
-- Strip HTML and ASS tags.
|
-- Strip HTML and ASS tags.
|
||||||
for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do
|
for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do
|
||||||
-- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.
|
-- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.
|
||||||
sub_times[#sub_times + 1] = line:match("%d+") * 60 + line:match(":([%d%.]*)")
|
sub_times[#sub_times + 1] = line:match("%d+") * 60 + line:match(":([%d%.]*)")
|
||||||
sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times]) .. " " ..
|
sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) ..
|
||||||
line:gsub(".*]", "", 1)
|
" " .. line:gsub(".*]", "", 1)
|
||||||
|
|
||||||
if sub_times[#sub_times] <= sub_start then
|
if sub_times[#sub_times] <= sub_start then
|
||||||
default_item = #sub_times
|
default_item = #sub_times
|
||||||
|
|
Loading…
Reference in New Issue