import sys
from database import get_session
from models import Performance, Show, Song
from sqlmodel import select, col

def check_videos():
    video_ids = [
        "PvdtMSifDqU", "7vujKUzGtcg", "nCnYJaIxBzo", "Yeno3bJs4Ws", 
        "zQI6-LloYwI", "F66jL0skeT4", "JdWnhOIWh-I", "wtTiAwA5Ha4", 
        "USQNba0t-4A", "vCdiwBSGtpk", "1BbtYhhCMWs", "yCPFRcIByqI", 
        "vE1F77CZbXQ", "rek58BRByTw", "rhP0-gKD_d8", "jMhayG6WCIw", 
        "osPxSR5GmX8", "cyLYgo9r3xM", "nZE_w8hDukI", "W93zvUz4vyI"
    ]
    
    session = next(get_session())
    found_count = 0
    missing = []
    
    print(f"Checking {len(video_ids)} videos...")
    
    for vid in video_ids:
        # Check Shows
        s = session.exec(select(Show).where(Show.youtube_link.contains(vid))).first()
        if s:
            print(f"[FOUND] {vid}: Show {s.date}")
            found_count += 1
            continue
            
        # Check Performances
        p = session.exec(select(Performance).where(Performance.youtube_link.contains(vid))).first()
        if p:
             # Get song title
            song = session.get(Song, p.song_id)
            print(f"[FOUND] {vid}: Performance {song.title} (Show {p.show_id})")
            found_count += 1
            continue
            
        # Check Songs (Direct link)
        song = session.exec(select(Song).where(Song.youtube_link.contains(vid))).first()
        if song:
            print(f"[FOUND] {vid}: Song Master {song.title}")
            found_count += 1
            continue
            
        print(f"[MISSING] {vid}")
        missing.append(vid)

    print(f"\nSummary: Found {found_count}/{len(video_ids)}")
    print(f"Missing IDs: {missing}")

if __name__ == "__main__":
    check_videos()
