Omit the hour in the chapter and subtitle line selectors when the file is shorter than an hour.
Showing the changes to player/lua/select.lua (1 of 1 file). Show all
Unified · Split
| @@ -149,13 +149,17 @@ mp.add_forced_key_binding(nil, "select-vid", function () · 148 unmodified lines | ||
| 149 | 149 | "No available video tracks.") |
| 150 | 150 | end) |
| 151 | 151 | |
| 152 | −local function format_time(t) | |
| 152 | +local function format_time(t, duration) | |
| 153 | 153 | local h = math.floor(t / (60 * 60)) |
| 154 | 154 | t = t - (h * 60 * 60) |
| 155 | 155 | local m = math.floor(t / 60) |
| 156 | 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) | |
| 159 | 163 | end |
| 160 | 164 | |
| 161 | 165 | 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 | ||
| 167 | 171 | return |
| 168 | 172 | end |
| 169 | 173 | |
| 174 | + local duration = mp.get_property_native("duration", math.huge) | |
| 175 | + | |
| 170 | 176 | 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 | |
| 172 | 178 | end |
| 173 | 179 | |
| 174 | 180 | input.select({ |
| @@ -213,13 +219,14 @@ mp.add_forced_key_binding(nil, "select-subtitle-line", function () · 38 unmodified lines | ||
| 213 | 219 | local default_item |
| 214 | 220 | local sub_start = mp.get_property_native("sub-start", |
| 215 | 221 | mp.get_property_native("time-pos")) |
| 222 | + local duration = mp.get_property_native("duration", math.huge) | |
| 216 | 223 | |
| 217 | 224 | -- Strip HTML and ASS tags. |
| 218 | 225 | for line in r.stdout:gsub("<.->", ""):gsub("{\\.-}", ""):gmatch("[^\n]+") do |
| 219 | 226 | -- ffmpeg outputs LRCs with minutes > 60 instead of adding hours. |
| 220 | 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]) .. " " .. | |
| 222 | − line:gsub(".*]", "", 1) | |
| 228 | + sub_lines[#sub_lines + 1] = format_time(sub_times[#sub_times], duration) .. | |
| 229 | + " " .. line:gsub(".*]", "", 1) | |
| 223 | 230 | |
| 224 | 231 | if sub_times[#sub_times] <= sub_start then |
| 225 | 232 | default_item = #sub_times |