added changes

This commit is contained in:
2026-01-17 12:14:36 -05:00
parent f9639318e8
commit f7107ff2a6
7 changed files with 3666 additions and 14 deletions
+19 -11
View File
@@ -253,22 +253,30 @@ def check_srt_duration_match(source_srt_path, target_srt_path, tolerance_seconds
"""
Compares the duration of two SRT files to ensure they cover roughly the same timeframe.
Useful for detecting partial translations.
Args:
source_srt_path (str): Path to the original language SRT.
target_srt_path (str): Path to the translated SRT.
tolerance_seconds (float): Max allowed difference in seconds.
tolerance_percent (float): Max allowed difference as a percentage of source duration.
Returns:
tuple: (bool, str) -> (passed, message)
"""
if not os.path.exists(source_srt_path) or not os.path.exists(target_srt_path):
return False, "One or both SRT files missing."
def load_subs_robust(path):
# Try detected encoding first
detected_enc = detect_file_encoding(path)
try:
return pysubs2.load(path, encoding=detected_enc)
except Exception:
pass
# Fallback encodings
encodings = ['utf-8', 'cp1252', 'latin-1', 'utf-16', 'shift_jis']
for enc in encodings:
try:
return pysubs2.load(path, encoding=enc)
except Exception:
continue
raise Exception(f"Could not decode {os.path.basename(path)} with any standard encoding.")
try:
source_subs = pysubs2.load(source_srt_path)
target_subs = pysubs2.load(target_srt_path)
source_subs = load_subs_robust(source_srt_path)
target_subs = load_subs_robust(target_srt_path)
except Exception as e:
return False, f"Error parsing SRTs: {e}"