#!/usr/bin/env python
"""
Example of subtitle functionality in FMUS-VID.

This script demonstrates how to add subtitles to videos.
"""

import sys
import os
from pathlib import Path

# Add the parent directory to the path so we can import fmusvid
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from fmusvid import Video

def main():
    """Run the subtitle example."""
    print("FMUS-VID Subtitle Example")
    print("=========================")

    # Load a video
    input_path = input("Enter path to input video: ")
    video = Video(input_path)

    # Print video info
    info = video.info()
    print(f"\nVideo Information:\n{info}")

    # Example 1: Add subtitles from a file
    subtitle_choice = input("\nDo you want to add subtitles from a file? (y/n): ")

    if subtitle_choice.lower() == 'y':
        subtitle_path = input("Enter path to subtitle file (.srt or .vtt): ")

        if os.path.exists(subtitle_path):
            # Add subtitles
            video.add_subtitles(
                subtitle_path,
                font="Arial",
                size=24,
                color="white"
            )
            print(f"Added subtitles from {subtitle_path}")

    # Example 2: Add custom subtitle text
    text_choice = input("\nDo you want to add custom subtitle text? (y/n): ")

    if text_choice.lower() == 'y':
        # Add custom subtitle text
        text = input("Enter subtitle text: ")
        start_time = float(input("Enter start time (seconds): "))
        end_time = float(input("Enter end time (seconds): "))

        video.add_subtitle_text(
            text=text,
            start_time=start_time,
            end_time=end_time,
            font="Arial",
            size=28,
            color="yellow"
        )
        print(f"Added custom subtitle: '{text}' from {start_time}s to {end_time}s")

    # Save the result
    output_path = input("\nEnter path for output video: ")
    print(f"Saving video to {output_path}...")
    video.save(output_path)
    print("Done!")

if __name__ == "__main__":
    main()
