Clipping / tests /test_10s_process.py
aliSaac510's picture
ading sentens to the suptitle
2e6074b
import json
import os
import sys
# Setup path
current_dir = os.path.dirname(os.path.abspath(__file__))
clipping_dir = os.path.dirname(current_dir)
if clipping_dir not in sys.path:
sys.path.append(clipping_dir)
try:
from fastapi.testclient import TestClient
from main import app
from routers.video import ORIGINALS_DIR
except ImportError as e:
print(f"❌ Error: Missing dependencies. Please run 'pip install -r requirements.txt'")
print(f"Details: {e}")
sys.exit(1)
client = TestClient(app)
def create_10s_mock_video(filename="test_10s_video.mp4"):
path = os.path.join(ORIGINALS_DIR, filename)
if not os.path.exists(path):
import imageio_ffmpeg
import subprocess
exe = imageio_ffmpeg.get_ffmpeg_exe()
subprocess.run([
exe, '-f', 'lavfi', '-i', 'testsrc=duration=10:size=1280x720:rate=30',
'-f', 'lavfi', '-i', 'sine=frequency=1000:duration=10',
'-c:v', 'libx264', '-t', '10', path, '-y'
], capture_output=True)
return filename
def test_10s_workflow():
video_name = create_10s_mock_video()
# اختبار 1: استخدام وضع الكلمات التقليدي (Word Mode) مع بريسيت gaming
transcription_words = [
{"word": "Hello", "start": 0.0, "end": 1.0},
{"word": "this", "start": 1.0, "end": 2.0},
{"word": "is", "start": 2.0, "end": 3.0},
{"word": "a", "start": 3.0, "end": 4.0},
{"word": "test", "start": 4.0, "end": 5.0}
]
# اختبار 2: استخدام وضع الجمل والمزامنة اليدوية (Sentence Mode) مع بريسيت storyteller
transcription_sentences = [
{
"text": "This is a test of the storyteller mode",
"start": 5.0,
"end": 10.0,
"words": [
{"word": "This", "start": 5.0, "end": 6.0},
{"word": "is", "start": 6.0, "end": 7.0},
{"word": "a", "start": 7.0, "end": 8.0},
{"word": "test", "start": 8.0, "end": 9.0},
{"word": "of", "start": 9.0, "end": 9.5},
{"word": "the", "start": 9.5, "end": 10.0}
]
}
]
timestamps = [{"start_time": 0, "end_time": 10}]
# تنفيذ الاختبار الأول (Word Mode)
print(f"\n--- Running Test 1: Word Mode with 'gaming' preset ---")
process_data_1 = {
"original_filename": video_name,
"aspect_ratio": "9:16",
"style": "cinematic",
"subtitle_style": "gaming",
"transcription": json.dumps(transcription_words),
"timestamps": json.dumps(timestamps)
}
resp1 = client.post("/api/video/process-saved", data=process_data_1)
if resp1.status_code == 200:
print(f"✅ Word Mode Success! Task ID: {resp1.json()['task_id']}")
else:
print(f"❌ Word Mode Failed: {resp1.text}")
# تنفيذ الاختبار الثاني (Sentence Mode - المزامنة اليدوية)
print(f"\n--- Running Test 2: Sentence Mode with 'storyteller' preset ---")
process_data_2 = {
"original_filename": video_name,
"aspect_ratio": "9:16",
"style": "cinematic",
"subtitle_style": "storyteller",
"transcription": json.dumps(transcription_sentences),
"timestamps": json.dumps(timestamps)
}
resp2 = client.post("/api/video/process-saved", data=process_data_2)
if resp2.status_code == 200:
result = resp2.json()
print(f"✅ Sentence Mode Success! Task ID: {result['task_id']}")
print(f"✅ Clip URL: {result['clips_urls'][0]}")
else:
print(f"❌ Sentence Mode Failed: {resp2.text}")
if __name__ == "__main__":
test_10s_workflow()