"""Smoke test PornDoeScraper — fetch sample + sprawdz parsing."""
import logging

logging.basicConfig(level=logging.INFO)

from app.connectors.direct_scrapers.porndoe import PornDoeScraper


def main():
    scraper = PornDoeScraper()
    print(f"sitetag: {scraper.sitetag}")
    print(f"listing url p1: {scraper._listing_url(1)}")
    print(f"listing url p2: {scraper._listing_url(2)}")
    print()

    count = 0
    ok_studio = ok_perf = ok_date = ok_dur = ok_thumb = ok_phash = 0
    for scene in scraper.latest_scenes(max_pages=1):
        count += 1
        if scene.studio:
            ok_studio += 1
        if scene.performers:
            ok_perf += 1
        if scene.release_date:
            ok_date += 1
        if scene.duration_sec:
            ok_dur += 1
        if scene.playback_sources and scene.playback_sources[0].thumbnail_url:
            ok_thumb += 1
        if scene.fingerprints:
            ok_phash += 1
        if count <= 5:
            print(f"--- scene {count} ---")
            print(f"  ext_id:   {scene.external_id}")
            print(f"  title:    {scene.title[:60]}")
            print(f"  studio:   {scene.studio.name if scene.studio else None}")
            print(f"  perf:     {[p.name for p in scene.performers]}")
            print(f"  date:     {scene.release_date}")
            print(f"  duration: {scene.duration_sec}s")
            print(f"  tags:     {[t.name for t in scene.tags][:5]}")
            print(f"  thumb:    {(scene.playback_sources[0].thumbnail_url or '')[:70]}")
            print(f"  phash:    {[f.value for f in scene.fingerprints]}")
            print()
        if count >= 15:
            break

    print("=" * 50)
    print(f"total scraped: {count}")
    if count:
        print(f"  studio:    {ok_studio}/{count} ({100*ok_studio//count}%)")
        print(f"  performer: {ok_perf}/{count} ({100*ok_perf//count}%)")
        print(f"  date:      {ok_date}/{count} ({100*ok_date//count}%)")
        print(f"  duration:  {ok_dur}/{count} ({100*ok_dur//count}%)")
        print(f"  thumbnail: {ok_thumb}/{count} ({100*ok_thumb//count}%)")
        print(f"  phash:     {ok_phash}/{count} ({100*ok_phash//count}%)")


if __name__ == "__main__":
    main()
