"""YouPorn.com — direct HTML scrape search results.

Search: `https://www.youporn.com/search/?query=<q>&page=<n>`
Scene URL: `https://www.youporn.com/watch/<id>/<slug>/`
"""
from __future__ import annotations

import re

from app.connectors.direct_scrapers._search_base import BaseSearchScraper


class YouPornScraper(BaseSearchScraper):
    sitetag = "youporncom"
    _search_url_template = "https://www.youporn.com/search/?query={query}&page={page}"
    _scene_url_re = re.compile(
        r'href="(?P<url>/watch/(?P<id>\d+)/(?P<slug>[a-z0-9_\-]+))/?"',
        re.IGNORECASE,
    )

    def _slug_from_match(self, m, scene_url):
        return m.group("slug")
