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 | "No available video tracks.") | 149 | "No available video tracks.") |
| 150 | end) | 150 | end) |
| 151 | 151 | ||
| 152 | local function format_time(t) | 152 | local 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) | ||
| 159 | end | 163 | end |
| 160 | 164 | ||
| 161 | mp.add_forced_key_binding(nil, "select-chapter", function () | 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 | return | 171 | return |
| 168 | end | 172 | 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")) do | 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 | end | 178 | 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_item | 219 | 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]+") do | 225 | 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 then | 231 | if sub_times[#sub_times] <= sub_start then |
| 225 | default_item = #sub_times | 232 | default_item = #sub_times |