123 lines
4.8 KiB
Python
Executable File
123 lines
4.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import os
|
|
import sys
|
|
import argparse
|
|
import socket
|
|
from dotenv import load_dotenv
|
|
from tqdm import tqdm
|
|
|
|
# Load config
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
env_path = os.path.abspath(os.path.join(script_dir, '../../.env_files/.env.aitranscribe'))
|
|
if os.path.exists(env_path):
|
|
load_dotenv(env_path)
|
|
else:
|
|
load_dotenv()
|
|
|
|
from utils import check_srt_duration_match, check_path_permissions, detect_file_encoding
|
|
|
|
def analyze_directory(folder_path, target_lang="English"):
|
|
print(f"🔍 Analyzing {folder_path} for broken/partial translations...")
|
|
|
|
# Check Permissions
|
|
perm_ok, perm_msg = check_path_permissions(folder_path)
|
|
if not perm_ok:
|
|
print(perm_msg)
|
|
return
|
|
|
|
issues_found = []
|
|
total_scanned = 0
|
|
|
|
# Walk through directory
|
|
for root, dirs, files in os.walk(folder_path):
|
|
for file in files:
|
|
if file.endswith(".srt") and \
|
|
not file.endswith(f".{target_lang}.srt") and \
|
|
not file.endswith(f".{target_lang}.deep_translate.srt") and \
|
|
not file.endswith(f".{target_lang}.local_llm.srt") and \
|
|
not file.endswith(".invalid") and \
|
|
not file.endswith(".failed_validation"):
|
|
|
|
source_srt_path = os.path.join(root, file)
|
|
base_name = os.path.splitext(file)[0]
|
|
|
|
# Paths to check
|
|
path_gemini = os.path.join(root, f"{base_name}.{target_lang}.srt")
|
|
path_deep = os.path.join(root, f"{base_name}.{target_lang}.deep_translate.srt")
|
|
path_local = os.path.join(root, f"{base_name}.{target_lang}.local_llm.srt")
|
|
|
|
existing_translation_path = None
|
|
method = "None"
|
|
|
|
if os.path.exists(path_local):
|
|
existing_translation_path = path_local
|
|
method = "Local LLM"
|
|
elif os.path.exists(path_gemini):
|
|
existing_translation_path = path_gemini
|
|
method = "Gemini"
|
|
elif os.path.exists(path_deep):
|
|
existing_translation_path = path_deep
|
|
method = "DeepTranslate"
|
|
|
|
total_scanned += 1
|
|
|
|
if existing_translation_path:
|
|
# Validate duration
|
|
is_valid, msg = check_srt_duration_match(source_srt_path, existing_translation_path)
|
|
if not is_valid:
|
|
issues_found.append({
|
|
"source": source_srt_path,
|
|
"translation": existing_translation_path,
|
|
"method": method,
|
|
"reason": msg
|
|
})
|
|
else:
|
|
# Missing translation
|
|
issues_found.append({
|
|
"source": source_srt_path,
|
|
"translation": "MISSING",
|
|
"method": "None",
|
|
"reason": "No translation file found."
|
|
})
|
|
|
|
# --- Report ---
|
|
print("\n" + "="*50)
|
|
print(f"📊 Analysis Report for: {folder_path}")
|
|
print("="*50)
|
|
print(f"Total Source Transcripts Scanned: {total_scanned}")
|
|
print(f"Issues Found: {len(issues_found)}")
|
|
print("-" * 50)
|
|
|
|
if issues_found:
|
|
print("Detailed Issues:")
|
|
for i, issue in enumerate(issues_found, 1):
|
|
print(f"{i}. {os.path.basename(issue['source'])}")
|
|
print(f" Target: {os.path.basename(issue['translation']) if issue['translation'] != 'MISSING' else 'MISSING'}")
|
|
print(f" Error: {issue['reason']}")
|
|
print("-" * 30)
|
|
|
|
# Optional: Save to file
|
|
report_file = f"analysis_report_{socket.gethostname()}.txt"
|
|
with open(report_file, "w", encoding="utf-8") as f:
|
|
f.write(f"Analysis Report - {datetime.now().isoformat()}\n")
|
|
for issue in issues_found:
|
|
f.write(f"{issue['source']} | {issue['reason']}\n")
|
|
print(f"\nReport saved to: {report_file}")
|
|
else:
|
|
print("✅ No issues found! All translations appear healthy.")
|
|
|
|
if __name__ == "__main__":
|
|
from datetime import datetime
|
|
|
|
parser = argparse.ArgumentParser(description="Analyze Translations (Read-Only)")
|
|
parser.add_argument("folders", nargs='+', help="One or more paths to folders to scan")
|
|
parser.add_argument("--lang", default="English", help="Target language (default: English)")
|
|
|
|
args = parser.parse_args()
|
|
|
|
for folder in args.folders:
|
|
if os.path.exists(folder):
|
|
analyze_directory(folder, args.lang)
|
|
else:
|
|
print(f"Error: Folder '{folder}' does not exist. Skipping.")
|