fix update session

This commit is contained in:
2025-08-29 01:02:13 -07:00
parent 4cacc648a8
commit f4a2c6012f

View File

@@ -42,6 +42,9 @@ local session_start_time = nil
local video_info = {} local video_info = {}
local is_tracking = false local is_tracking = false
-- Forward declaration for update_session_progress
local update_session_progress
-- Utility functions -- Utility functions
local function log(message) local function log(message)
if options.enable_debug_logging then if options.enable_debug_logging then
@@ -200,10 +203,7 @@ local function save_session_to_csv()
tonumber(current_session.duration) or 0, tonumber(current_session.duration) or 0,
current_session.start_timestamp or "", current_session.start_timestamp or "",
current_session.end_timestamp or current_session.start_timestamp or "", current_session.end_timestamp or current_session.start_timestamp or "",
tonumber(current_session.total_watch_time) tonumber(current_session.total_watch_time) or (get_current_timestamp() and session_start_time and (get_current_timestamp() - session_start_time) or 0),
or (
get_current_timestamp and session_start_time and (get_current_timestamp() - session_start_time) or 0
),
tonumber(current_session.watch_progress) or 0, tonumber(current_session.watch_progress) or 0,
current_session.video_format or "", current_session.video_format or "",
current_session.audio_format or "", current_session.audio_format or "",
@@ -325,6 +325,9 @@ local function end_current_session()
return return
end end
-- Ensure the latest playback position is saved
update_session_progress()
local end_time = get_current_timestamp() local end_time = get_current_timestamp()
current_session.end_time = end_time current_session.end_time = end_time
current_session.end_timestamp = format_timestamp(end_time) current_session.end_timestamp = format_timestamp(end_time)
@@ -426,7 +429,7 @@ local function start_new_session()
end end
end end
local function update_session_progress() update_session_progress = function()
if not current_session or not is_tracking then if not current_session or not is_tracking then
return return
end end