REMOVE unused "clean_old_ts_files()"
Also renamed undescriptive "save()" to "combine_last_x_ts_files()"
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from rewind.video import save, clean_old_ts_files
|
from rewind.video import combine_last_x_ts_files
|
||||||
import obsws_python as obs
|
import obsws_python as obs
|
||||||
import sys, argparse
|
import sys, argparse
|
||||||
|
|
||||||
@@ -10,12 +10,11 @@ def start_recording(con):
|
|||||||
|
|
||||||
def stop_recording(con):
|
def stop_recording(con):
|
||||||
con.stop_record()
|
con.stop_record()
|
||||||
clean_old_ts_files(con.get_record_directory().record_directory, max_age_seconds=0)
|
|
||||||
print("Stopped recording")
|
print("Stopped recording")
|
||||||
|
|
||||||
def create_recording(seconds):
|
def create_recording(seconds):
|
||||||
output_file_name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4"
|
output_file_name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}.mp4"
|
||||||
save(seconds, output_file_name)
|
combine_last_x_ts_files(seconds, output_file_name)
|
||||||
print(f"Created clip: {output_file_name}")
|
print(f"Created clip: {output_file_name}")
|
||||||
|
|
||||||
def build_parser():
|
def build_parser():
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import os, subprocess, datetime, json
|
|||||||
|
|
||||||
from rewind.paths import load_state
|
from rewind.paths import load_state
|
||||||
|
|
||||||
def save(seconds, output_file):
|
def combine_last_x_ts_files(seconds: float, output_file: str) -> None:
|
||||||
ts_files = load_state().get("files", [])
|
ts_files = load_state().get("files", [])
|
||||||
ts_files[-1]["duration"] = get_duration(ts_files[-1]["path"])
|
ts_files[-1]["duration"] = get_duration(ts_files[-1]["path"])
|
||||||
|
|
||||||
@@ -28,17 +28,7 @@ def save(seconds, output_file):
|
|||||||
|
|
||||||
os.remove("file_list.txt")
|
os.remove("file_list.txt")
|
||||||
|
|
||||||
def clean_old_ts_files(record_dir, max_age_seconds=60*60*3):
|
def get_duration(file_path: str) -> float:
|
||||||
current_time = datetime.datetime.now().timestamp()
|
|
||||||
for filename in os.listdir(record_dir):
|
|
||||||
if filename.endswith(".ts"):
|
|
||||||
file_path = os.path.join(record_dir, filename)
|
|
||||||
file_age = current_time - os.path.getmtime(file_path)
|
|
||||||
if file_age > max_age_seconds:
|
|
||||||
os.remove(file_path)
|
|
||||||
print(f"Deleted old file: {file_path}")
|
|
||||||
|
|
||||||
def get_duration(file_path):
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["ffprobe", "-v", "error", "-show_entries",
|
["ffprobe", "-v", "error", "-show_entries",
|
||||||
"format=duration", "-of",
|
"format=duration", "-of",
|
||||||
|
|||||||
Reference in New Issue
Block a user