goon/app/connectors/direct_scrapers/porntrex.py
goon-foss ad0284585b Initial commit
Goon — self-hosted aggregator for adult-content scene metadata.

Indexes scenes from TPDB, StashDB, and 30+ public adult tube sites.
Cross-source deduplication via perceptual hash + Levenshtein distance.
FastAPI backend + APScheduler worker + React Native (Expo) mobile client.

FOSS, ad-free, donation-funded. See README for details.
2026-05-20 10:10:22 +02:00

33 lines
1.2 KiB
Python

"""PornTrex.com — direct HTML scrape search results.
Search: `https://www.porntrex.com/search/<q>/` (single page, brak ?page=).
Scene URL: `https://www.porntrex.com/video/<id>/<slug>/`
Porntrex pagination niespójne między widokami — używamy `?from=<offset>` gdy page>1.
"""
from __future__ import annotations
import re
from app.connectors.direct_scrapers._search_base import BaseSearchScraper
class PornTrexScraper(BaseSearchScraper):
sitetag = "porntrexcom"
_search_url_template = "https://www.porntrex.com/search/{query}/"
_scene_url_re = re.compile(
r'href="(?P<url>https://www\.porntrex\.com/video/\d+/(?P<slug>[a-z0-9_\-]+))/?"',
re.IGNORECASE,
)
def search(self, query, *, page=1, limit=None):
# Porntrex używa offset w URL gdy page > 1: `/search/<q>/?from_videos=<page>`
if page > 1:
original = self._search_url_template
self._search_url_template = f"{original.rstrip('/')}/?from_videos={page}"
try:
yield from super().search(query, page=page, limit=limit)
finally:
self._search_url_template = original
else:
yield from super().search(query, page=page, limit=limit)