Skip to content

Commit

Permalink
feat(add): 大幅度提升 unreal 执行效率
Browse files Browse the repository at this point in the history
  • Loading branch information
QIN2DIM committed Apr 15, 2022
1 parent 284fb23 commit 841ea39
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 100 deletions.
38 changes: 16 additions & 22 deletions src/services/bricklayer/bricklayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def __init__(self, auth_str="games"):

self.action_name = "CookieManager"
self.service_mode = auth_str
self.ctx_session = None

def _t(self) -> str:
return (
Expand Down Expand Up @@ -121,11 +122,12 @@ def is_available_cookie(self, ctx_cookies: Optional[List[dict]] = None) -> bool:
return False

def refresh_ctx_cookies(
self, silence: bool = True, _ctx_session=None
self, silence: bool = True, _ctx_session=None, _keep_live=None
) -> Optional[bool]:
"""
更新上下文身份信息
:param _keep_live: keep actively to the challenger context
:param _ctx_session: 泛型开发者参数
:param silence:
:return:
Expand Down Expand Up @@ -225,7 +227,10 @@ def refresh_ctx_cookies(
return self.is_available_cookie(ctx_cookies=ctx.get_cookies())
finally:
if _ctx_session is None:
ctx.quit()
if not _keep_live:
ctx.quit()
else:
self.ctx_session = ctx
# {{< Done >}}

return True
Expand All @@ -248,13 +253,13 @@ def get_free_game(
ctx_cookies: List[dict] = None,
refresh: bool = True,
challenge: Optional[bool] = None,
_ctx_session=None,
ctx_session=None,
) -> Optional[bool]:
"""
获取免费游戏
部署后必须传输有效的 `page_link` 参数。
:param _ctx_session:
:param ctx_session:
:param challenge:
:param page_link: 游戏购买页链接 zh-CN
:param refresh: 当 COOKIE 失效时主动刷新 COOKIE
Expand Down Expand Up @@ -284,10 +289,10 @@ def get_free_game(
return False

# [🚀] 常驻免费(General)周免(Challenge)
if _ctx_session is None:
if ctx_session is None:
ctx = get_challenge_ctx(self.silence) if challenge else get_ctx(self.silence)
else:
ctx = _ctx_session
ctx = ctx_session

# [🚀] 认领游戏
try:
Expand Down Expand Up @@ -337,31 +342,20 @@ def get_free_game(
)
return False
finally:
if _ctx_session is None:
if ctx_session is None:
ctx.quit()

def get_free_dlc_details(
self, ctx_url: str, ctx_cookies: List[dict]
) -> Optional[List[Dict[str, Union[str, bool]]]]:
"""
:param ctx_cookies:
:param ctx_url: 游戏本体链接
:return:
"""
"""获取免费附加内容信息"""
dlc_details = self._get_free_dlc_details(ctx_url, ctx_cookies)
if not dlc_details:
return []
return dlc_details

def get_free_resources(self, page_link: str, ctx_cookies: List[dict], ctx_session):
"""
:param ctx_cookies:
:param page_link:
:param ctx_session:
:return:
"""
return self._get_free_resources(
def get_free_games(self, page_link: str, ctx_cookies: List[dict], ctx_session):
"""获取周免资源 游戏本体/附加内容 集成接口"""
return self._get_free_resource(
page_link=page_link, ctx_cookies=ctx_cookies, ctx=ctx_session
)
2 changes: 1 addition & 1 deletion src/services/bricklayer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def handle_html(url_):

return list(dlc_details.values())

def _get_free_resources(self, page_link: str, ctx_cookies: List[dict], ctx: Chrome):
def _get_free_resource(self, page_link: str, ctx_cookies: List[dict], ctx: Chrome):
return self._get_free_game(page_link=page_link, api_cookies=ctx_cookies, ctx=ctx)

def _unreal_activate_payment(
Expand Down
10 changes: 6 additions & 4 deletions src/services/bricklayer/unreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author : QIN2DIM
# Github : https://github.com/QIN2DIM
# Description:
from typing import List, Optional, Dict
from typing import List, Optional, Dict, Union

from bs4 import BeautifulSoup
from cloudscraper import create_scraper
Expand Down Expand Up @@ -31,7 +31,9 @@ class UnrealClaimer(Bricklayer):
def __init__(self, silence: Optional[bool] = None):
super().__init__(silence=silence, auth_str="unreal")

def get_claimer_response(self, ctx_cookies: List[dict]) -> List[Dict[str, str]]:
def get_claimer_response(
self, ctx_cookies: List[dict]
) -> List[Dict[str, Union[str, bool]]]:
"""领取任务后审查资源的在库状态"""
headers = {"cookie": ToolBox.transfer_cookies(ctx_cookies)}
scraper = create_scraper()
Expand All @@ -51,9 +53,9 @@ def get_claimer_response(self, ctx_cookies: List[dict]) -> List[Dict[str, str]]:

return details

def get_free_resource(self, ctx, ctx_cookies):
def get_free_unreal_content(self, ctx_session, ctx_cookies):
try:
self._unreal_get_free_resource(ctx=ctx, ctx_cookies=ctx_cookies)
self._unreal_get_free_resource(ctx=ctx_session, ctx_cookies=ctx_cookies)
except AssertTimeout:
logger.debug(
ToolBox.runtime_report(
Expand Down
Loading

0 comments on commit 841ea39

Please sign in to comment.