FlareSolverr-фолбэк для загрузки по ссылке; -ReleaseUrl в predict.ps1
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
bc9ff36e61
commit
dce219aeee
6 files changed
+150
-10
No files matched your search
@@ -236,5 +236,51 @@ _t5 = "Русский MVO HDRezka Studio"
|
||||
check("span: расширение до границ слова", _t5[slice(*refine_span(_t5, (12, 14)))] == "HDRezka")
|
||||
check("span: один символ -> None", refine_span("М. Чадов", (0, 1)) is None)
|
||||
|
||||
import json as _json # noqa: E402
|
||||
import threading # noqa: E402
|
||||
import urllib.error # noqa: E402
|
||||
from http.server import BaseHTTPRequestHandler, HTTPServer # noqa: E402
|
||||
|
||||
import src.fetch as _fetch # noqa: E402
|
||||
|
||||
|
||||
class _FakeFlare(BaseHTTPRequestHandler):
|
||||
def do_POST(self):
|
||||
req = _json.loads(self.rfile.read(int(self.headers["Content-Length"])))
|
||||
ok = req.get("cmd") == "request.get" and "rutracker.org" in req.get("url", "")
|
||||
body = _json.dumps({"status": "ok", "solution": {"response": "<html>Перевод: Дублированный | MovieDalen</html>"}}
|
||||
if ok else {"status": "error", "message": "bad"}).encode()
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
|
||||
_srv = HTTPServer(("127.0.0.1", 0), _FakeFlare)
|
||||
threading.Thread(target=_srv.serve_forever, daemon=True).start()
|
||||
_flare = f"http://127.0.0.1:{_srv.server_port}"
|
||||
|
||||
|
||||
def _deny(url, timeout, cookie):
|
||||
raise urllib.error.HTTPError(url, 403, "Forbidden", {}, None)
|
||||
|
||||
|
||||
_orig = _fetch._fetch_direct
|
||||
_fetch._fetch_direct = _deny
|
||||
try:
|
||||
h, tr = _fetch.fetch_html("https://rutracker.org/forum/viewtopic.php?t=1", flaresolverr=_flare)
|
||||
check("FlareSolverr: fallback при 403", "MovieDalen" in h and tr == "rutracker")
|
||||
try:
|
||||
_fetch.fetch_html("https://rutracker.org/forum/viewtopic.php?t=1")
|
||||
check("без FlareSolverr 403 пробрасывается", False)
|
||||
except urllib.error.HTTPError:
|
||||
check("без FlareSolverr 403 пробрасывается", True)
|
||||
finally:
|
||||
_fetch._fetch_direct = _orig
|
||||
_srv.shutdown()
|
||||
|
||||
|
||||
print(f"\nитог: {PASS} ok, {FAIL} failed")
|
||||
sys.exit(1 if FAIL else 0)
|
||||
Reference in new issue
Block a user