trackers: опциональный обход Cloudflare через FlareSolverr - #81
Merged
mdevaev merged 1 commit intoSep 11, 2026
Merged
Conversation
Some trackers (rutracker.org in particular) now put a Cloudflare "Just a moment..." interstitial in front of endpoints such as /forum/login.php, which returns HTTP 403 to the plain urllib client and kills the run at tracker.login(). Add two opt-in per-tracker options, flaresolverr_url (default "", i.e. disabled) and flaresolverr_timeout. When flaresolverr_url is set and a request gets a 403, the request is routed once through a FlareSolverr instance: emonoda adopts the exact User-Agent FlareSolverr used and injects the returned cookies (notably cf_clearance) into its cookie jar, then retries the request directly. The cf_clearance cookie is bound to UA + egress IP, so adopting FlareSolverr's UA is mandatory and emonoda must share the same egress IP as FlareSolverr. The FlareSolverr client is a small stdlib-only JSON POST helper (emonoda/web/flaresolverr.py), no new third-party dependencies. When flaresolverr_url is empty the behaviour is byte-for-byte unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
Owner
|
Шикарно, спасибо. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема
Некоторые трекеры (в первую очередь rutracker.org) стали закрывать часть эндпоинтов интерстициалом Cloudflare («Just a moment…»). В частности, rutracker.org/forum/login.php теперь отдаёт HTTP 403 обычному urllib-клиенту emonoda, и каждый запуск падает на tracker.login() с NetworkError(HTTPError: HTTP Error 403: Forbidden). При этом index.php челленджем не закрыт — под защитой только часть эндпоинтов, включая логин.
Решение
Добавлена опциональная поддержка FlareSolverr — сервиса, который решает Cloudflare-челлендж в headless-браузере и возвращает cookie cf_clearance вместе с User-Agent, которым он пользовался.
Появились две новые пер-трекерные опции (в BaseTracker, поэтому доступны всем трекерам):
Логика встроена в единственную точку входа HTTP-запросов трекера (__read_url_nofe): лениво, только при получении 403 и только если flaresolverr_url задан. При срабатывании:
Ключевая деталь: cf_clearance привязан к UA + IP
Выданный Cloudflare cf_clearance действителен только для той пары User-Agent + внешний IP, которой был решён челлендж. Поэтому подмена UA — не деталь, а обязательное условие: без неё повторный прямой запрос снова получит 403. Соответственно, emonoda и FlareSolverr должны иметь один и тот же внешний IP (в моём случае оба сервиса ходят наружу через один NAT-адрес кластера). Это описано в документации к опции.
Обратная совместимость
Изменения не затрагивают trackers/*.json (там только версия и fingerprint), так что make regen-trackers не требуется.
Известное ограничение
test() для проверки fingerprint создаёт отдельный opener без cookie. У rutracker fingerprint-URL — это index.php, который челленджем не закрыт, поэтому на практике в CF он не упирается; при желании обработку 403 можно позже распространить и на этот путь.
Как тестировалось