"""Test stream extraction on 2 lessons."""
import asyncio
import sys
from pathlib import Path
sys.stdout.reconfigure(encoding="utf-8")

# Patch to only test 2 lessons
import extract_streams as es

async def test():
    lessons = [
        {"num": 1, "title": "Introduccion a RAIO", "vidalytics_id": "wihR3kVLVbphHxSJ", "stream_url": None},
        {"num": 3, "title": "Presenting Yourself", "vidalytics_id": "tzRWrTefukz6FKVn", "stream_url": None},
    ]
    from playwright.async_api import async_playwright
    async with async_playwright() as pw:
        browser = await pw.chromium.launch(headless=True)
        ctx = await browser.new_context(
            user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/124 Safari/537.36",
            viewport={"width": 1280, "height": 800},
        )
        page = await ctx.new_page()
        for lesson in lessons:
            print(f"\nTesting: {lesson['title']} ({lesson['vidalytics_id']})")
            url = await es.get_stream_url(page, lesson['vidalytics_id'], lesson['title'])
            print(f"  Result: {url or 'NONE'}")
        await page.close()
        await browser.close()

asyncio.run(test())
