"""Create one finished original Minecraft story Short."""
import argparse
import json
from pathlib import Path

from story import save_story
from tts import generate_tts
from render import render_short

parser = argparse.ArgumentParser()
parser.add_argument("--footage", type=Path, default=Path("footage/orbital/orbital_LwqyaFWDey8.mp4"))
parser.add_argument("--offset", type=float, default=300.0)
parser.add_argument("--stem", default="the_lookout_note")
args = parser.parse_args()

STEM = args.stem
FOOTAGE = args.footage
STORY = (
    "Someone had been leaving a single dirt block outside my Minecraft base every night. "
    "At first, I thought it was a prank. Then the blocks started forming a path. "
    "The path led through the forest, across a ravine, and straight to an abandoned mineshaft. "
    "Inside, I found a chest with one sign: DO NOT DIG DOWN. "
    "Naturally, I dug down. "
    "The tunnel dropped into a hidden room packed with diamonds, maps, and a second sign. "
    "It said, YOU FOUND MY EMERGENCY STASH. PLEASE TAKE HALF. "
    "Before I could celebrate, a lever clicked behind me. "
    "The exit opened, revealing another player in full diamond armor. "
    "They waved, handed me a cake, and pointed at the maps. "
    "Every map showed my base from a different angle. "
    "I asked how long they had been watching me. "
    "They answered, \"Long enough to know you always dig down.\""
)

story = {
    "title": "The Dirt Blocks Outside My Base",
    "story": STORY,
    "description": "A Minecraft mystery leads to an underground surprise. Footage: Orbital - No Copyright Gameplay. #minecraft #storytime #shorts",
    "hashtags": ["#shorts", "#minecraft", "#storytime", "#gaming"],
    "theme": "Minecraft mystery with an ironic twist",
    "source": "original-fiction",
    "footage_source": "Orbital - No Copyright Gameplay",
    "footage_url": "https://www.youtube.com/watch?v=LwqyaFWDey8",
    "footage_license": "Creative Commons Attribution license (reuse allowed)",
    "footage_credit": "Orbital - No Copyright Gameplay",
}
story, stem = save_story(story, STEM)
mp3, ass, duration = generate_tts(story["story"], stem)
output = render_short(mp3, ass, duration, stem, start_offset=args.offset, footage_path=FOOTAGE)
print(json.dumps({
    "title": story["title"],
    "words": len(story["story"].split()),
    "duration": duration,
    "story": str(Path("stories") / f"{stem}.json"),
    "audio": str(mp3),
    "subtitles": str(ass),
    "output": str(output),
}, indent=2))
