#!/usr/bin/env python3
"""Test Arabic text overlay functionality"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

from app.services.text_overlay import TextOverlayService

def test_arabic_overlay():
    """Test Arabic text overlay service"""
    print("🔄 Testing Arabic text overlay service...")

    try:
        service = TextOverlayService()

        # Check ffmpeg
        if not service.ffmpeg_path:
            print("❌ ffmpeg not found")
            return False
        print(f"✅ ffmpeg found: {service.ffmpeg_path}")

        # Check Arabic fonts
        font_path = service.get_arabic_font_path("Noto")
        if not os.path.exists(font_path):
            print(f"❌ Arabic font not found: {font_path}")
            return False
        print(f"✅ Arabic font found: {font_path}")

        # Test Arabic rendering
        print("🎬 Testing Arabic text rendering...")
        result = service.test_arabic_rendering()

        if result.get("status") == "success":
            print("✅ Arabic text rendering works!")
            print(f"📹 Test video created: {result.get('test_video')}")
            print(f"⏱️ Duration: {result.get('duration')} seconds")
            return True
        else:
            print(f"❌ Arabic text rendering failed: {result.get('message')}")
            return False

    except Exception as e:
        print(f"❌ Test failed: {e}")
        import traceback
        traceback.print_exc()
        return False

if __name__ == "__main__":
    from app import create_app
    app = create_app()

    with app.app_context():
        success = test_arabic_overlay()
        sys.exit(0 if success else 1)