History

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.

Guido Cella committed 2 years ago

Commit 5657cd61 parent 8939bfc1 file · +12 −5Browse files

Showing the changes to player/lua/select.lua (1 of 1 file). Show all

Unified · Split

player/lua/select.lua+12−5
@@ -149,13 +149,17 @@ mp.add_forced_key_binding(nil, "select-vid", function () · 148 unmodified lines
149149 "No available video tracks.")
150150 end)
151151
152−local function format_time(t)
152+local function format_time(t, duration)
153153 local h = math.floor(t / (60 * 60))
154154 t = t - (h * 60 * 60)
155155 local m = math.floor(t / 60)
156156 local s = t - (m * 60)
157157
158− return string.format("%.2d:%.2d:%.2d", h, m, s)
158+ if duration >= 60 * 60 or h > 0 then
159+ return string.format("%.2d:%.2d:%.2d", h, m, s)
160+ end
161+
162+ return string.format("%.2d:%.2d", m, s)
159163 end
160164
161165 mp.add_forced_key_binding(nil, "select-chapter", function ()
@@ -167,8 +171,10 @@ mp.add_forced_key_binding(nil, "select-chapter", function () · 5 unmodified lines
167171 return
168172 end
169173
174+ local duration = mp.get_property_native("duration", math.huge)
175+
170176 for i, chapter in ipairs(mp.get_property_native("chapter-list")) do
171− chapters[i] = format_time(chapter.time) .. " " .. chapter.title
177+ chapters[i] = format_time(chapter.time, duration) .. " " .. chapter.title
172178 end
173179
174180 input.select({
@@ -213,13 +219,14 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () · 38 unmodified lines
213219 local default_item
214220 local sub_start = mp.get_property_native("sub-start",
215221 mp.get_property_native("time-pos"))
222+ local duration = mp.get_property_native("duration", math.huge)
216223
217224 -- Strip HTML and ASS tags.
218225 for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do
219226 -- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.
220227 sub_times[#sub_times + 1] = line:match("%d+") * 60 + line:match(":([%d%.]*)")
221− sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times]) .. " " ..
222− line:gsub(".*]", "", 1)
228+ sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) ..
229+ " " .. line:gsub(".*]", "", 1)
223230
224231 if sub_times[#sub_times] <= sub_start then
225232 default_item = #sub_times

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t