mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
fix addon passing all websites
This commit is contained in:
parent
0713ce7ca5
commit
9ca2059b91
7
main.py
7
main.py
@ -31,6 +31,7 @@ async def read_item(request: LinkRequest):
|
|||||||
logger.info(f"Request: {request}")
|
logger.info(f"Request: {request}")
|
||||||
start_time = int(time.time() * 1000)
|
start_time = int(time.time() * 1000)
|
||||||
browser = await new_browser()
|
browser = await new_browser()
|
||||||
|
await browser.grant_all_permissions()
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
page = await browser.get(request.url)
|
page = await browser.get(request.url)
|
||||||
await page.bring_to_front()
|
await page.bring_to_front()
|
||||||
@ -39,8 +40,12 @@ async def read_item(request: LinkRequest):
|
|||||||
timeout = None
|
timeout = None
|
||||||
try:
|
try:
|
||||||
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
|
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError as e:
|
||||||
logger.info("Timed out bypassing Cloudflare")
|
logger.info("Timed out bypassing Cloudflare")
|
||||||
|
raise HTTPException(
|
||||||
|
detail="Timed out bypassing Cloudflare", status_code=408
|
||||||
|
) from e
|
||||||
|
browser.stop()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
browser.stop()
|
browser.stop()
|
||||||
raise HTTPException(detail="Couldn't bypass", status_code=408) from e
|
raise HTTPException(detail="Couldn't bypass", status_code=408) from e
|
||||||
|
@ -4,7 +4,7 @@ import nodriver as webdriver
|
|||||||
from nodriver.core.element import Element
|
from nodriver.core.element import Element
|
||||||
|
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src.utils.consts import CHALLENGE_TITLES
|
from src.utils.consts import CHALLENGE_TITLES, UBLOCK_TITLE
|
||||||
from src.utils.extentions import download_extentions
|
from src.utils.extentions import download_extentions
|
||||||
|
|
||||||
downloaded_extentions = download_extentions()
|
downloaded_extentions = download_extentions()
|
||||||
@ -58,11 +58,13 @@ async def bypass_cloudflare(page: webdriver.Tab):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
challenged = False
|
challenged = False
|
||||||
|
await page
|
||||||
while True:
|
while True:
|
||||||
await asyncio.sleep(1)
|
|
||||||
logger.debug(f"Current page: {page.target.title}")
|
logger.debug(f"Current page: {page.target.title}")
|
||||||
|
|
||||||
if page.target.title not in CHALLENGE_TITLES:
|
if page.target.title not in CHALLENGE_TITLES:
|
||||||
|
if page.target.title == UBLOCK_TITLE:
|
||||||
|
continue
|
||||||
return challenged
|
return challenged
|
||||||
|
|
||||||
if not challenged:
|
if not challenged:
|
||||||
@ -78,12 +80,12 @@ async def bypass_cloudflare(page: webdriver.Tab):
|
|||||||
|
|
||||||
loaded = False
|
loaded = False
|
||||||
try:
|
try:
|
||||||
elem = await page.find("lds-ring")
|
elem = await page.find("lds-ring", timeout=3)
|
||||||
except asyncio.TimeoutError as e:
|
except asyncio.TimeoutError:
|
||||||
logger.error(
|
logger.error(
|
||||||
"Couldn't find lds-ring, probably not a cloudflare challenge, trying again..."
|
"Couldn't find lds-ring, probably not a cloudflare challenge, trying again..."
|
||||||
)
|
)
|
||||||
raise InvalidElementError from e
|
continue
|
||||||
if elem is None:
|
if elem is None:
|
||||||
logger.error("elem is None")
|
logger.error("elem is None")
|
||||||
logger.debug(elem)
|
logger.debug(elem)
|
||||||
@ -115,7 +117,7 @@ async def bypass_cloudflare(page: webdriver.Tab):
|
|||||||
logger.debug("Clicking element")
|
logger.debug("Clicking element")
|
||||||
await inner_elem.mouse_click()
|
await inner_elem.mouse_click()
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
else:
|
continue
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Couldn't find element containing shadow root, trying again..."
|
"Couldn't find element containing shadow root, trying again..."
|
||||||
)
|
)
|
||||||
|
@ -5,6 +5,8 @@ from pathlib import Path
|
|||||||
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
|
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
|
||||||
LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
|
LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
|
||||||
|
|
||||||
|
UBLOCK_TITLE = "uBO Lite — Dashboard"
|
||||||
|
|
||||||
CHALLENGE_TITLES = [
|
CHALLENGE_TITLES = [
|
||||||
# Cloudflare
|
# Cloudflare
|
||||||
"Just a moment...",
|
"Just a moment...",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user