refactor(ts_files): move ts file state fetch out of media

This commit is contained in:
2026-04-29 21:31:24 +01:00
parent 7b6780bd86
commit 96f20a714c
2 changed files with 16 additions and 6 deletions

View File

@@ -22,7 +22,9 @@ def clip(seconds_from_end: float) -> None:
end_timestamp = datetime.datetime.now().timestamp() end_timestamp = datetime.datetime.now().timestamp()
length = end_timestamp - start_timestamp length = end_timestamp - start_timestamp
ts_files = [f for f in load_state()["files"] if os.path.exists(f["path"])]
files, start_offset, end_offset = get_ts_files( files, start_offset, end_offset = get_ts_files(
ts_files,
start_timestamp, start_timestamp,
end_timestamp end_timestamp
) )
@@ -43,7 +45,10 @@ def save(first_marker: str, second_marker: str):
output_file_name = f"{datetime.datetime.fromtimestamp(first_timestamp).strftime('%Y-%m-%d_%H:%M:%S')}-[{first_marker}-{second_marker}].mp4" output_file_name = f"{datetime.datetime.fromtimestamp(first_timestamp).strftime('%Y-%m-%d_%H:%M:%S')}-[{first_marker}-{second_marker}].mp4"
output_path = os.path.join(vod_dir, output_file_name) output_path = os.path.join(vod_dir, output_file_name)
ts_files = [f for f in load_state()["files"] if os.path.exists(f["path"])]
files, start_offset, end_offset = get_ts_files( files, start_offset, end_offset = get_ts_files(
ts_files,
first_timestamp, first_timestamp,
second_timestamp second_timestamp
) )

View File

@@ -11,8 +11,11 @@ Returns a list of file paths and extra start and end offsets if needed.
get_duration() is used as little as possible since it is slow. get_duration() is used as little as possible since it is slow.
end_timestamp of a file is the start time of the next file. end_timestamp of a file is the start time of the next file.
""" """
def get_ts_files(start_timestamp: float, end_timestamp: float) -> tuple[list[str], float, float]: def get_ts_files(
ts_files = [f for f in load_state()["files"] if os.path.exists(f["path"])] ts_files: list[dict],
start_timestamp: float,
end_timestamp: float
) -> tuple[list[str], float, float]:
selected_files = [] selected_files = []
start_offset = 0.0 start_offset = 0.0
end_offset = 0.0 end_offset = 0.0
@@ -28,10 +31,12 @@ def get_ts_files(start_timestamp: float, end_timestamp: float) -> tuple[list[str
selected_files.append(file_info["path"]) selected_files.append(file_info["path"])
if file_start <= start_timestamp < file_end: if file_start < start_timestamp:
start_offset = start_timestamp - file_start start_offset = start_timestamp - file_start
if file_start < end_timestamp <= file_end:
if file_end >= end_timestamp:
end_offset = file_end - end_timestamp end_offset = file_end - end_timestamp
break
return selected_files, start_offset, end_offset return selected_files, start_offset, end_offset