goon/app/connectors/direct_scrapers/xhamster.py
goon-foss c55596dd6f fix(thumbs): xhamster miniatury z JSON strony wynikow, mypornerleak z src i og:image posta, backfill brakujacych
- _search_base: hak _thumbnail_map (mapa url -> miniatura z calej strony) przed
  szukaniem <img> w oknie tekstu; xhamster mial 54% zrodel bez miniatury
- mypornerleak search: karty maja teraz src zamiast data-src; browse (REST) bez
  featured media -> og:image ze strony posta
- scripts/backfill_thumbs.py: uzupelnia miniatury ze strony sceny, od najnowszych

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-14 14:33:51 +02:00

32 lines
1.2 KiB
Python

"""XHamster.com, direct HTML scrape search results.
Search: `https://xhamster.com/search/<q>?page=<n>`
Scene URL: `https://xhamster.com/videos/<slug>-<id>`
"""
from __future__ import annotations
import re
# Karty sa renderowane z JSON-a w HTML (`window.initials`): kazda ma `pageURL` i
# `thumbURL` (526x298 webp). Szukanie `<img>` w oknie tekstu gubilo polowe scen, bo
# ten sam link wystepuje dwa razy (miniatura i tytul), a img jest tylko przy pierwszym.
_JSON_CARD_RE = re.compile(
r'"pageURL":"(https:\\/\\/xhamster\.com\\/videos\\/[^"]+)","thumbURL":"([^"]+)"'
)
from app.connectors.direct_scrapers._search_base import BaseSearchScraper
class XHamsterScraper(BaseSearchScraper):
sitetag = "xhamstercom"
_search_url_template = "https://xhamster.com/search/{query}?page={page}"
_scene_url_re = re.compile(
r'href="(?P<url>https://xhamster\.com/videos/(?P<slug>[a-z0-9_\-]+))"',
re.IGNORECASE,
)
def _thumbnail_map(self, listing_html: str) -> dict[str, str]:
out: dict[str, str] = {}
for page_url, thumb in _JSON_CARD_RE.findall(listing_html):
out[page_url.replace("\\/", "/")] = thumb.replace("\\/", "/")
return out