Last active
April 29, 2022 07:57
-
-
Save TheAMM/82b2a114bdf4cda219951260f4982156 to your computer and use it in GitHub Desktop.
Simple mpv Lua script for displaying the expected end time for the current file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
Simple script to display the end-time for the current file. | |
Example input.conf bind: | |
E script-message display-eta | |
]]-- | |
local utils = require("mp.utils") | |
local SCRIPT_COMMAND_NAME = 'display-eta' | |
function display_eta() | |
local playback_time = mp.get_property_native("playback-time") | |
local duration = mp.get_property_native("duration") | |
if playback_time and duration then | |
local playback_speed = mp.get_property_native("speed") | |
local remaining_time = (duration - playback_time) / playback_speed | |
local current_time = os.time() | |
local end_time = current_time + remaining_time | |
-- Check if the date changes and adjust the format string | |
local current_time_table = os.date("*t", current_time) | |
local end_time_table = os.date("*t", end_time) | |
local same_day = current_time_table.year == end_time_table.year and current_time_table.month == end_time_table.month and current_time_table.day == end_time_table.day | |
local format_string = same_day and "%H:%M" or "%H:%M (%A)" | |
local formatted_time = os.date(format_string, end_time) | |
mp.osd_message("ETA: " .. formatted_time, 2) | |
else | |
mp.osd_message("Unable to estimate ending time") | |
end | |
end | |
mp.add_key_binding("E", SCRIPT_COMMAND_NAME, display_eta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment