feat: 抖音登录态检测逻辑更新支持

This commit is contained in:
Relakkes 2024-05-23 22:15:14 +08:00
parent 3c4695eed7
commit 764bafc626
7 changed files with 23 additions and 10 deletions

View File

@ -95,7 +95,7 @@
> 7天有效期自动更新, 如果人满了可以加作者wx拉进群: yzglan备注来自github. > 7天有效期自动更新, 如果人满了可以加作者wx拉进群: yzglan备注来自github.
<div style="max-width: 200px"> <div style="max-width: 200px">
<p><img alt="8群二维码" src="static/images/8群二维码.JPG" style="width: 200px;height: 100%" ></p> <p><img alt="9群二维码" src="static/images/9群二维码.PNG" style="width: 200px;height: 100%" ></p>
</div> </div>
@ -115,6 +115,8 @@
➡️➡️➡️ [常见问题](docs/常见问题.md) ➡️➡️➡️ [常见问题](docs/常见问题.md)
抖音使用Playwright登录现在会出现滑块验证 + 短信验证,手动过一下
## 项目代码结构 ## 项目代码结构
➡️➡️➡️ [项目代码结构说明](docs/项目代码结构.md) ➡️➡️➡️ [项目代码结构说明](docs/项目代码结构.md)

View File

@ -56,13 +56,15 @@ class AbstractStore(ABC):
async def store_creator(self, creator: Dict): async def store_creator(self, creator: Dict):
pass pass
class AbstractStoreImage(ABC): class AbstractStoreImage(ABC):
#TODO: support all platform # TODO: support all platform
# only weibo is supported # only weibo is supported
# @abstractmethod # @abstractmethod
async def store_image(self, image_content_item: Dict): async def store_image(self, image_content_item: Dict):
pass pass
class AbstractApiClient(ABC): class AbstractApiClient(ABC):
@abstractmethod @abstractmethod
async def request(self, method, url, **kwargs): async def request(self, method, url, **kwargs):
@ -71,7 +73,3 @@ class AbstractApiClient(ABC):
@abstractmethod @abstractmethod
async def update_cookies(self, browser_context: BrowserContext): async def update_cookies(self, browser_context: BrowserContext):
pass pass
@abstractmethod
async def pong(self):
pass

View File

@ -19,7 +19,7 @@ IP_PROXY_PROVIDER_NAME = "kuaidaili"
# 设置False会打开一个浏览器 # 设置False会打开一个浏览器
# 小红书如果一直扫码登录不通过,打开浏览器手动过一下滑动验证码 # 小红书如果一直扫码登录不通过,打开浏览器手动过一下滑动验证码
# 抖音如果一直提示失败,打开浏览器看下是否扫码登录之后出现了手机号验证,如果出现了手动过一下再试。 # 抖音如果一直提示失败,打开浏览器看下是否扫码登录之后出现了手机号验证,如果出现了手动过一下再试。
HEADLESS = True HEADLESS = False
# 是否保存登录状态 # 是否保存登录状态
SAVE_LOGIN_STATE = True SAVE_LOGIN_STATE = True

View File

@ -86,10 +86,12 @@ class DOUYINClient(AbstractApiClient):
headers = headers or self.headers headers = headers or self.headers
return await self.request(method="POST", url=f"{self._host}{uri}", data=data, headers=headers) return await self.request(method="POST", url=f"{self._host}{uri}", data=data, headers=headers)
@staticmethod async def pong(self, browser_context: BrowserContext) -> bool:
async def pong(browser_context: BrowserContext) -> bool: local_storage = await self.playwright_page.evaluate("() => window.localStorage")
if local_storage.get("HasUserLogin", "") == "1":
return True
_, cookie_dict = utils.convert_cookies(await browser_context.cookies()) _, cookie_dict = utils.convert_cookies(await browser_context.cookies())
# todo send some api to test login status
return cookie_dict.get("LOGIN_STATUS") == "1" return cookie_dict.get("LOGIN_STATUS") == "1"
async def update_cookies(self, browser_context: BrowserContext): async def update_cookies(self, browser_context: BrowserContext):

View File

@ -73,8 +73,19 @@ class DouYinLogin(AbstractLogin):
"""Check if the current login status is successful and return True otherwise return False""" """Check if the current login status is successful and return True otherwise return False"""
current_cookie = await self.browser_context.cookies() current_cookie = await self.browser_context.cookies()
_, cookie_dict = utils.convert_cookies(current_cookie) _, cookie_dict = utils.convert_cookies(current_cookie)
for page in self.browser_context.pages:
try:
local_storage = await page.evaluate("() => window.localStorage")
if local_storage.get("HasUserLogin", "") == "1":
return True
except Exception as e:
utils.logger.warn(f"[DouYinLogin] check_login_state waring: {e}")
await asyncio.sleep(1)
if cookie_dict.get("LOGIN_STATUS") == "1": if cookie_dict.get("LOGIN_STATUS") == "1":
return True return True
return False return False
async def popup_login_dialog(self): async def popup_login_dialog(self):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB