Compare commits
3 Commits
5ff663e288
...
af73adf1aa
| Author | SHA1 | Date | |
|---|---|---|---|
| af73adf1aa | |||
| 3102ba50ad | |||
| 6e9b71f4cc |
@@ -112,7 +112,9 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
default_route_socketio(P, self)
|
default_route_socketio(P, self)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_html(url, referer=None, stream=False, timeout=5):
|
def get_html(
|
||||||
|
url: str, referer: str = None, stream: bool = False, timeout: int = 5
|
||||||
|
) -> str:
|
||||||
data = ""
|
data = ""
|
||||||
try:
|
try:
|
||||||
print("cloudflare protection bypass ==================")
|
print("cloudflare protection bypass ==================")
|
||||||
@@ -143,7 +145,9 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_html_requests(url, referer=None, stream=False, timeout=5):
|
def get_html_requests(
|
||||||
|
url: str, referer: str = None, stream: str = False, timeout: int = 5
|
||||||
|
) -> str:
|
||||||
data = ""
|
data = ""
|
||||||
try:
|
try:
|
||||||
print("get_html_requests ==================")
|
print("get_html_requests ==================")
|
||||||
@@ -173,14 +177,20 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_html_playwright(
|
async def get_html_playwright(
|
||||||
url, headless=False, referer=None, engine="chrome", stealth=False
|
url: str,
|
||||||
):
|
headless: bool = False,
|
||||||
|
referer: str = None,
|
||||||
|
engine: str = "chrome",
|
||||||
|
stealth: bool = False,
|
||||||
|
) -> str:
|
||||||
|
try:
|
||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
from playwright.async_api import async_playwright
|
from playwright.async_api import async_playwright
|
||||||
from playwright_stealth import stealth_sync, stealth_async
|
from playwright_stealth import stealth_sync, stealth_async
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
cookie = None
|
||||||
browser_args = [
|
browser_args = [
|
||||||
"--window-size=1300,570",
|
"--window-size=1300,570",
|
||||||
"--window-position=000,000",
|
"--window-position=000,000",
|
||||||
@@ -237,8 +247,8 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||||
"Chrome/69.0.3497.100 Safari/537.36"
|
"Chrome/69.0.3497.100 Safari/537.36"
|
||||||
)
|
)
|
||||||
|
|
||||||
# from playwright_stealth import stealth_sync
|
# from playwright_stealth import stealth_sync
|
||||||
cookie = None
|
|
||||||
|
|
||||||
def set_cookie(req):
|
def set_cookie(req):
|
||||||
nonlocal cookie
|
nonlocal cookie
|
||||||
@@ -246,6 +256,7 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
cookie = req.headers["cookie"]
|
cookie = req.headers["cookie"]
|
||||||
|
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
|
try:
|
||||||
if engine == "chrome":
|
if engine == "chrome":
|
||||||
browser = await p.chromium.launch(
|
browser = await p.chromium.launch(
|
||||||
channel="chrome", args=browser_args, headless=headless
|
channel="chrome", args=browser_args, headless=headless
|
||||||
@@ -264,7 +275,9 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
# user_agent=ua,
|
# user_agent=ua,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
LogicAniLife.headers["Referer"] = "https://anilife.live/detail/id/471"
|
LogicAniLife.headers[
|
||||||
|
"Referer"
|
||||||
|
] = "https://anilife.live/detail/id/471"
|
||||||
# print(LogicAniLife.headers)
|
# print(LogicAniLife.headers)
|
||||||
|
|
||||||
LogicAniLife.headers["Referer"] = LogicAniLife.episode_url
|
LogicAniLife.headers["Referer"] = LogicAniLife.episode_url
|
||||||
@@ -273,7 +286,9 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
LogicAniLife.headers["Referer"] = referer
|
LogicAniLife.headers["Referer"] = referer
|
||||||
|
|
||||||
logger.debug(f"LogicAniLife.headers::: {LogicAniLife.headers}")
|
logger.debug(f"LogicAniLife.headers::: {LogicAniLife.headers}")
|
||||||
context = await browser.new_context(extra_http_headers=LogicAniLife.headers)
|
context = await browser.new_context(
|
||||||
|
extra_http_headers=LogicAniLife.headers
|
||||||
|
)
|
||||||
await context.add_cookies(LogicAniLife.cookies)
|
await context.add_cookies(LogicAniLife.cookies)
|
||||||
|
|
||||||
# LogicAniLife.headers["Cookie"] = cookie_value
|
# LogicAniLife.headers["Cookie"] = cookie_value
|
||||||
@@ -316,6 +331,18 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
print(f"run at {time.time() - start} sec")
|
print(f"run at {time.time() - start} sec")
|
||||||
|
|
||||||
return await page.content()
|
return await page.content()
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Exception:%s", e)
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
finally:
|
||||||
|
await browser.close()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Exception:%s", e)
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
finally:
|
||||||
|
# browser.close()
|
||||||
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_vod_url_v1(
|
async def get_vod_url_v1(
|
||||||
@@ -421,7 +448,7 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
return await page.content()
|
return await page.content()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_vod_url(url, headless=False):
|
async def get_vod_url(url: str, headless: bool = False) -> str:
|
||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
from playwright.async_api import async_playwright
|
from playwright.async_api import async_playwright
|
||||||
from playwright_stealth import stealth_async
|
from playwright_stealth import stealth_async
|
||||||
@@ -488,6 +515,7 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
# from playwright_stealth import stealth_sync
|
# from playwright_stealth import stealth_sync
|
||||||
|
|
||||||
async with async_playwright() as p:
|
async with async_playwright() as p:
|
||||||
|
try:
|
||||||
# browser = await p.chromium.launch(headless=headless, args=browser_args)
|
# browser = await p.chromium.launch(headless=headless, args=browser_args)
|
||||||
browser = await p.chromium.launch(headless=headless, args=browser_args)
|
browser = await p.chromium.launch(headless=headless, args=browser_args)
|
||||||
|
|
||||||
@@ -568,30 +596,15 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
|
|
||||||
logger.debug(f"run at {time.time() - start} sec")
|
logger.debug(f"run at {time.time() - start} sec")
|
||||||
|
|
||||||
# html_content = LogicAniLife.get_html_selenium(
|
|
||||||
# vod_url, "https://anilife.live"
|
|
||||||
# )
|
|
||||||
|
|
||||||
# html_content = LogicAniLife.get_html_playwright(
|
|
||||||
# vod_url, False, referer="https://anilife.live"
|
|
||||||
# )
|
|
||||||
|
|
||||||
# html_content = LogicAniLife.get_html(
|
|
||||||
# vod_url, referer="https://anilife.live"
|
|
||||||
# )
|
|
||||||
# html_content = LogicAniLife.get_html_requests(
|
|
||||||
# vod_url, referer="https://anilife.live"
|
|
||||||
# )
|
|
||||||
|
|
||||||
# print(f"html_content:: {html_content}")
|
|
||||||
# output_json = html_to_json.convert(html_content)
|
|
||||||
# resolution = output_json["html"][0]["body"][0]["_value"]
|
|
||||||
# logger.debug(f"output_json:: {resolution}")
|
|
||||||
|
|
||||||
return vod_url
|
return vod_url
|
||||||
|
except Exception as e:
|
||||||
|
logger.error("Exception:%s", e)
|
||||||
|
logger.error(traceback.format_exc())
|
||||||
|
finally:
|
||||||
|
await browser.close()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_html_selenium(url, referer):
|
def get_html_selenium(url: str, referer: str) -> str:
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium_stealth import stealth
|
from selenium_stealth import stealth
|
||||||
@@ -654,6 +667,8 @@ class LogicAniLife(LogicModuleBase):
|
|||||||
elem = driver.find_element(By.XPATH, "//*")
|
elem = driver.find_element(By.XPATH, "//*")
|
||||||
source_code = elem.get_attribute("outerHTML")
|
source_code = elem.get_attribute("outerHTML")
|
||||||
|
|
||||||
|
driver.close()
|
||||||
|
|
||||||
return source_code.encode("utf-8")
|
return source_code.encode("utf-8")
|
||||||
|
|
||||||
# Create a request interceptor
|
# Create a request interceptor
|
||||||
@@ -1130,7 +1145,7 @@ class AniLifeQueueEntity(FfmpegQueueEntity):
|
|||||||
self.module_logic.socketio_callback("status", self.as_dict())
|
self.module_logic.socketio_callback("status", self.as_dict())
|
||||||
|
|
||||||
def info_dict(self, tmp):
|
def info_dict(self, tmp):
|
||||||
logger.debug("self.info::> %s", self.info)
|
# logger.debug("self.info::> %s", self.info)
|
||||||
for key, value in self.info.items():
|
for key, value in self.info.items():
|
||||||
tmp[key] = value
|
tmp[key] = value
|
||||||
tmp["vtt"] = self.vtt
|
tmp["vtt"] = self.vtt
|
||||||
|
|||||||
Reference in New Issue
Block a user