From e66c8fbf88ec788512b4c2adbef72560fb911dfd Mon Sep 17 00:00:00 2001 From: Michael <42828375+sarmong@users.noreply.github.com> Date: Tue, 27 Dec 2022 10:17:12 +0200 Subject: [PATCH] feat: added `destination_time` option and deprecated `total_time` (#399) `destination_time` accepts one of `total`, `playtime-remaining` (scaled by the current speed), `time-remaining` (remaining length of file). `total_time` is deprecated, but still works as expected. --- script-opts/uosc.conf | 4 ++-- scripts/uosc.lua | 23 +++++++++++++++++------ scripts/uosc_shared/elements/Timeline.lua | 4 ++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/script-opts/uosc.conf b/script-opts/uosc.conf index a203e32..2574646 100644 --- a/script-opts/uosc.conf +++ b/script-opts/uosc.conf @@ -163,8 +163,8 @@ background=000000 background_text=ffffff # Use only bold font weight throughout the whole UI font_bold=no -# Show total time instead of time remaining -total_time=no +# One of `total`, `playtime-remaining` (scaled by the current speed), `time-remaining` (remaining length of file) +destination_time=playtime-remaining # Display sub second fraction in timestamps up to this precision time_precision=0 # Display stream's buffered time in timeline if it's lower than this amount of seconds, 0 to disable diff --git a/scripts/uosc.lua b/scripts/uosc.lua index 007d4f6..393bed5 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -88,7 +88,8 @@ defaults = { foreground_text = '000000', background = '000000', background_text = 'ffffff', - total_time = false, + total_time = false, -- deprecated by below + destination_time = 'playtime-remaining', time_precision = 0, font_bold = false, autohide = false, @@ -112,6 +113,12 @@ if options.pause_on_click_shorter_than > 0 and options.click_threshold == 0 then msg.warn('`pause_on_click_shorter_than` is deprecated. Use `click_threshold` and `click_command` instead.') options.click_threshold = options.pause_on_click_shorter_than end +if options.total_time and options.destination_time == 'playtime-remaining' then + msg.warn('`total_time` is deprecated. Use `destination_time` instead.') + options.destination_time = 'total' +elseif not itable_index_of({'total', 'playtime-remaining', 'time-remaining'}, options.destination_time) then + options.destination_time = 'playtime-remaining' +end -- Ensure required environment configuration if options.autoload then mp.commandv('set', 'keep-open-pause', 'no') end -- Color shorthands @@ -285,7 +292,7 @@ state = { speed = 1, duration = nil, -- current media duration time_human = nil, -- current playback time in human format - duration_or_remaining_time_human = nil, -- depends on options.total_time + destination_time_human = nil, -- depends on options.destination_time pause = mp.get_property_native('pause'), chapters = {}, current_chapter = nil, @@ -369,11 +376,15 @@ function update_human_times() state.time_human = format_time(state.time) if state.duration then local speed = state.speed or 1 - state.duration_or_remaining_time_human = format_time( - options.total_time and state.duration or ((state.time - state.duration) / speed) - ) + if options.destination_time == 'playtime-remaining' then + state.destination_time_human = format_time((state.time - state.duration) / speed) + elseif options.destination_time == 'total' then + state.destination_time_human = format_time(state.duration) + else + state.destination_time_human = format_time(state.time - state.duration) + end else - state.duration_or_remaining_time_human = nil + state.destination_time_human = nil end else state.time_human = nil diff --git a/scripts/uosc_shared/elements/Timeline.lua b/scripts/uosc_shared/elements/Timeline.lua index 39825f2..68bd725 100644 --- a/scripts/uosc_shared/elements/Timeline.lua +++ b/scripts/uosc_shared/elements/Timeline.lua @@ -333,8 +333,8 @@ function Timeline:render() end -- End time - if state.duration_or_remaining_time_human then - draw_timeline_text(bbx - spacing, fcy, 6, state.duration_or_remaining_time_human, time_opts) + if state.destination_time_human then + draw_timeline_text(bbx - spacing, fcy, 6, state.destination_time_human, time_opts) end end