Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions script-opts/SimpleHistory.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ toggle_idlescreen=no
#--change to 0 so item resumes from the exact position, or decrease the value so that it gives you a little preview before loading the resume point
resume_offset=-0.65

#--periodically save if the current playback position has changed by more than this many seconds. Set to 0 to totally disable periodic saving. This must be disabled to dynamically edit the history file and resume from the edited version.
periodic_save_min_offset=0

#--yes is for displaying osd messages when actions occur. Change to no will disable all osd messages generated from this script
osd_messages=yes

Expand Down
25 changes: 23 additions & 2 deletions scripts/SimpleHistory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ local o = {
startup_idle_behavior = 'none', --The behavior when mpv launches and nothing is loaded. 'none' for disabled. 'resume' to automatically resume your last played item. 'resume-notime' to resume your last played item but starts from the beginning.
toggle_idlescreen = false, --hides OSC idle screen message when opening and closing menu (could cause unexpected behavior if multiple scripts are triggering osc-idlescreen off)
resume_offset = -0.65, --change to 0 so item resumes from the exact position, or decrease the value so that it gives you a little preview before loading the resume point
periodic_save_min_offset = 0, --periodically save if the current playback position has changed by more than this many seconds. Set to 0 to totally disable periodic saving. This must be disabled to dynamically edit the history file and resume from the edited version.
osd_messages = true, --true is for displaying osd messages when actions occur. Change to false will disable all osd messages generated from this script
resume_option = 'notification', --'none': for disabled. 'notification': a message to resume the previous reached time will be triggered. 'force': to forcefully resume last playback based on threshold
resume_option_threshold = 2, --0 to always trigger the resume option when the same video has been played previously, a value such as 5 will only trigger the resume option if the last played time starts after 5% of the video and ends before completion by 5%
Expand Down Expand Up @@ -2183,10 +2184,15 @@ end

function history_resume()
if filePath == nil then
list_contents = read_log_table()
--# periodic save isn't compatible with the log table being updated during playback
if o.periodic_save_min_offset == 0 then
list_contents = read_log_table()
end
load(1)
elseif filePath ~= nil then
list_contents = read_log_table()
if o.periodic_save_min_offset == 0 then
list_contents = read_log_table()
end
if list_contents ~= nil and list_contents[1] then
for i = #list_contents, 1, -1 do
if list_contents[i].found_path == filePath and tonumber(list_contents[i].found_time) > 0 then
Expand Down Expand Up @@ -2220,6 +2226,21 @@ function history_load_last()
end
end

mp.add_periodic_timer(1, function()
if o.periodic_save_min_offset > 0 and not incognito_mode then
-- Don't fill the log file needlessly, especially if the player is paused
local prevLogTime = logTime
local newLogTime = (mp.get_property_number('time-pos') or 0)
if math.abs(newLogTime - prevLogTime) > o.periodic_save_min_offset then
logTime = newLogTime
local f = io.open(log_fullpath, "a+")
f:write(("[%s] \"%s\" | %s | %s | %s"):format(os.date(o.date_format), fileTitle, filePath, log_length_text .. tostring(fileLength), log_time_text .. tostring(logTime)))
f:write('\n')
f:close()
end
end
end)

mp.register_event('file-loaded', function()
list_close_and_trash_collection()
filePath, fileTitle, fileLength = get_file()
Expand Down