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
149 "No available video tracks.")149 "No available video tracks.")
150end)150end)
151 151
152local function format_time(t)152local function format_time(t, duration)
153 local h = math.floor(t / (60 * 60))153 local h = math.floor(t / (60 * 60))
154 t = t - (h * 60 * 60)154 t = t - (h * 60 * 60)
155 local m = math.floor(t / 60)155 local m = math.floor(t / 60)
156 local s = t - (m * 60)156 local s = t - (m * 60)
157 157
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)
159end163end
160 164
161mp.add_forced_key_binding(nil, "select-chapter", function ()165mp.add_forced_key_binding(nil, "select-chapter", function ()
@@ -167,8 +171,10 @@ mp.add_forced_key_binding(nil, "select-chapter", function () · 5 unmodified lines
167 return171 return
168 end172 end
169 173
174 local duration = mp.get_property_native("duration", math.huge)
175
170 for i, chapter in ipairs(mp.get_property_native("chapter-list")) do176 for i, chapter in ipairs(mp.get_property_native("chapter-list")) do
171 chapters[i] = format_time(chapter.time) .. " " .. chapter.title177 chapters[i] = format_time(chapter.time, duration) .. " " .. chapter.title
172 end178 end
173 179
174 input.select({180 input.select({
@@ -213,13 +219,14 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () · 38 unmodified lines
213 local default_item219 local default_item
214 local sub_start = mp.get_property_native("sub-start",220 local sub_start = mp.get_property_native("sub-start",
215 mp.get_property_native("time-pos"))221 mp.get_property_native("time-pos"))
222 local duration = mp.get_property_native("duration", math.huge)
216 223
217 -- Strip HTML and ASS tags.224 -- Strip HTML and ASS tags.
218 for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do225 for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do
219 -- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.226 -- ffmpeg outputs LRCs with minutes > 60 instead of adding hours.
220 sub_times[#sub_times + 1] = line:match("%d+") * 60 + line:match(":([%d%.]*)")227 sub_times[#sub_times + 1] = line:match("%d+") * 60 + line:match(":([%d%.]*)")
221 sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times]) .. " " ..228 sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) ..
222 line:gsub(".*]", "", 1)229 " " .. line:gsub(".*]", "", 1)
223 230
224 if sub_times[#sub_times] <= sub_start then231 if sub_times[#sub_times] <= sub_start then
225 default_item = #sub_times232 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