Hana Celeste commited on
Commit
31d7388
·
verified ·
1 Parent(s): dedf0c0

Update app/byps_logic.py

Browse files
Files changed (1) hide show
  1. app/byps_logic.py +91 -54
app/byps_logic.py CHANGED
@@ -1,55 +1,92 @@
1
- import aiohttp
2
  import asyncio
3
- import json
4
-
5
- CF_KEYWORDS = [
6
- "cloudflare",
7
- "__cf_bm",
8
- "cf-challenge",
9
- "Just a moment"
10
- ]
11
-
12
- def is_cloudflare(text: str) -> bool:
13
- t = text.lower()
14
- return any(k in t for k in CF_KEYWORDS)
15
-
16
-
17
- async def fetch_api(url: str, timeout=15):
18
- headers = {
19
- "User-Agent": (
20
- "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
21
- "AppleWebKit/537.36 (KHTML, like Gecko) "
22
- "Chrome/121.0.0.0 Safari/537.36"
23
- ),
24
- "Accept": "application/json, text/plain, */*",
25
- "Accept-Language": "en-US,en;q=0.9",
26
- "Referer": "https://ihentai.dog/",
27
- "Origin": "https://ihentai.dog",
28
- "Connection": "keep-alive",
29
- }
30
-
31
- async with aiohttp.ClientSession(headers=headers) as session:
32
- async with session.get(url, timeout=timeout) as resp:
33
- text = await resp.text()
34
-
35
- # Cloudflare silent bot fight
36
- if resp.status in (403, 429) or is_cloudflare(text):
37
- return {
38
- "ok": False,
39
- "error": "cloudflare_bot_fight",
40
- "status": resp.status
41
- }
42
-
43
- # Try JSON
44
- try:
45
- data = json.loads(text)
46
- return {
47
- "ok": True,
48
- "data": data
49
- }
50
- except json.JSONDecodeError:
51
- return {
52
- "ok": False,
53
- "error": "invalid_json",
54
- "raw": text[:200]
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import asyncio
2
+ import random
3
+ from playwright.async_api import async_playwright
4
+ from playwright_stealth import stealth_async
5
+
6
+
7
+ class BypsApp:
8
+ def __init__(self):
9
+ self.playwright = None
10
+ self.proxy_config = {
11
+ "server": "http://p.webshare.io:80",
12
+ "username": "szusjfnw-rotate",
13
+ "password": "mftzj9sljp5t"
14
+ }
15
+
16
+ async def start(self):
17
+ if not self.playwright:
18
+ self.playwright = await async_playwright().start()
19
+
20
+ async def stop(self):
21
+ if self.playwright:
22
+ await self.playwright.stop()
23
+ self.playwright = None
24
+
25
+ async def fetch(self, url: str):
26
+ if not self.playwright:
27
+ await self.start()
28
+
29
+ browser = None
30
+ try:
31
+ browser = await self.playwright.chromium.launch(
32
+ headless=False,
33
+ proxy=self.proxy_config,
34
+ args=[
35
+ "--no-sandbox",
36
+ "--disable-setuid-sandbox",
37
+ "--disable-dev-shm-usage",
38
+ "--disable-blink-features=AutomationControlled",
39
+ ]
40
+ )
41
+
42
+ context = await browser.new_context(
43
+ viewport={"width": 1280, "height": 720},
44
+ user_agent=(
45
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
46
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
47
+ "Chrome/122.0.0.0 Safari/537.36"
48
+ )
49
+ )
50
+
51
+ page = await context.new_page()
52
+
53
+ await stealth_async(page)
54
+
55
+ await page.goto(url, wait_until="domcontentloaded", timeout=60000)
56
+
57
+ for i in range(15):
58
+ title = await page.title()
59
+ html = await page.content()
60
+
61
+ if "just a moment" not in title.lower() and "cloudflare" not in html.lower():
62
+ break
63
+
64
+ try:
65
+ for frame in page.frames:
66
+ if "challenge" in frame.url or "turnstile" in frame.url:
67
+ box = await page.locator(
68
+ 'iframe[src*="challenge"], iframe[src*="turnstile"]'
69
+ ).bounding_box()
70
+ if box:
71
+ await page.mouse.click(
72
+ box["x"] + box["width"] / 2,
73
+ box["y"] + box["height"] / 2
74
+ )
75
+ except:
76
+ pass
77
+
78
+ await page.mouse.move(
79
+ random.randint(100, 600),
80
+ random.randint(100, 600)
81
+ )
82
+ await asyncio.sleep(3)
83
+
84
+ content = await page.content()
85
+ return {"ok": True, "data": content}
86
+
87
+ except Exception as e:
88
+ return {"ok": False, "error": str(e)}
89
+
90
+ finally:
91
+ if browser:
92
+ await browser.close()