import cv2
from pathlib import Path
from youtube_tab_to_pdf import extract_frames, detect_pattern, extract_unique_scroll, extract_unique_overlay, generate_pdf

video_path = Path("output/サカナクション／新宝島(エレキギターTAB) 難易度★★★ sakanaction shintakarajima.mp4")
output_pdf = Path("output/shintakarajima_perfect.pdf")

print("1. Extracting frames at 2fps...")
frames = extract_frames(video_path, fps=2.0)

pattern = detect_pattern(frames)
print(f"2. Detected Pattern: {pattern}")

if pattern == "overlay":
    final_chunks = extract_unique_overlay(frames)
else:
    final_chunks = extract_unique_scroll(frames)

print(f"3. Generating PDF with {len(final_chunks)} chunks...")
generate_pdf(final_chunks, output_pdf)

print(f"Done! PDF saved to {output_pdf}")
