"""Test: navega las primeras 3 lecciones y captura stream URLs."""
import asyncio
import json
import sys
sys.stdout.reconfigure(encoding="utf-8")

# Forzar que solo procese primeras 3
import extract_streams as es

# Usar solo 3 lecciones de prueba
LESSONS_TO_TEST = 3

orig_extract = es.extract_streams_from_clickfunnels

async def test_extract(lessons):
    # Solo las primeras 3 sin stream URL
    pending = [l for l in lessons if not l.get("stream_url")][:LESSONS_TO_TEST]
    others  = [l for l in lessons if l.get("stream_url")]
    all_lessons = pending + others
    # Modificar temporalmente max_lessons
    result = await orig_extract(pending)
    return result

async def main():
    lessons = json.loads(open("C:/xampp/htdocs/curso-riao/scripts/course_structure.json", encoding="utf-8").read())
    # Solo probar las 3 primeras sin stream URL
    test_lessons = [l for l in lessons if not l.get("stream_url")][:3]
    print(f"Probando con {len(test_lessons)} lecciones:")
    for l in test_lessons:
        print(f"  [{l['num']}] {l['title']} | {l['vidalytics_id']}")

    result = await es.extract_streams_from_clickfunnels(test_lessons)

    print("\nResultados:")
    for l in result:
        print(f"  [{l['num']}] {l['title'][:40]} | stream: {l.get('stream_url', 'NONE')[:80]}")

asyncio.run(main())
