import os
import sys

# Ensure ffmpeg in venv/Scripts is in PATH
venv_scripts = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'venv', 'Scripts')
if venv_scripts not in os.environ.get('PATH', ''):
    os.environ['PATH'] = venv_scripts + os.pathsep + os.environ.get('PATH', '')

import whisper

sys.stdout.reconfigure(encoding='utf-8')

video_path = sys.argv[1] if len(sys.argv) > 1 else r"content\videos\ep1.mp4"
model_name = sys.argv[2] if len(sys.argv) > 2 else "base"

print(f"Loading Whisper model '{model_name}'...")
model = whisper.load_model(model_name)

print(f"Transcribing {video_path} in Vietnamese...")
res = model.transcribe(video_path, language='vi')

for seg in res['segments']:
    print(f"{seg['start']:.1f}s -> {seg['end']:.1f}s: {seg['text']}")
