import os
import yt_dlp

VIDEOS = {
    "Forth Day 2020 - Preview of x64 & ColorForth & SPIR V - Onat.txt": "https://youtu.be/ajZAECYdJvE",
    "Neokineogfx - 4th And Beyond - Transcript.txt": "https://youtu.be/Awkdt30Ruvk",
    "Silicon Valley Forth Interest Group - Metaprogramming VAMP in KYRA, a Next-gen Forth-like language --- Onat Türkçüoğlu -- 2025-04-26.txt": "https://youtu.be/J9U_5tjdegY"
}

OUT_DIR = "C:/projects/forth/bootslop/references/processed_visuals"
os.makedirs(OUT_DIR, exist_ok=True)

ydl_opts = {
    'format': 'bestvideo[ext=mp4]/best',
    'quiet': False,
    'no_warnings': True,
}

for transcript_file, url in VIDEOS.items():
    video_name = os.path.splitext(transcript_file)[0]
    video_path = os.path.join(OUT_DIR, f"{video_name}.mp4")
    if not os.path.exists(video_path):
        print(f"Downloading {video_name}...")
        opts = ydl_opts.copy()
        opts['outtmpl'] = video_path
        with yt_dlp.YoutubeDL(opts) as ydl:
            ydl.download([url])
    else:
        print(f"{video_name} already exists.")
