refactor(types): govern unit3d site parser

This commit is contained in:
jxxghp
2026-10-17 01:18:49 +08:00
parent 767aa8896f
commit a4710b434d

View File

@@ -9,7 +9,7 @@ from app.foundation import size as size_tools
from app.foundation import temporal as time_tools
from app.foundation import text as text_tools
from app.foundation.dom import DomUtils
from app.modules.indexer.parser import SiteParserBase, SiteSchema
from app.modules.indexer.parser import SitePage, SiteParserBase, SiteSchema
class Unit3dSiteUserInfo(SiteParserBase):
@@ -17,7 +17,7 @@ class Unit3dSiteUserInfo(SiteParserBase):
schema = SiteSchema.Unit3d
def _parse_user_base_info(self, html_text: str):
def _parse_user_base_info(self, html_text: SitePage) -> None:
"""解析用户名并将 Unit3D 的用户名作为用户标识供后续请求使用。"""
html_text = self._prepare_html_text(html_text)
html = etree.HTML(html_text)
@@ -45,11 +45,11 @@ class Unit3dSiteUserInfo(SiteParserBase):
if html is not None:
del html
def _parse_site_page(self, html_text: str):
def _parse_site_page(self, html_text: SitePage) -> None:
"""Unit3D 不需要从站点首页解析额外的站点级数据。"""
pass
def _parse_user_detail_info(self, html_text: str):
def _parse_user_detail_info(self, html_text: str) -> None:
"""
解析用户额外信息,加入时间,等级
:param html_text:
@@ -129,7 +129,7 @@ class Unit3dSiteUserInfo(SiteParserBase):
return next_page
def _parse_user_traffic_info(self, html_text: str):
def _parse_user_traffic_info(self, html_text: str) -> None:
"""解析用户上传量、下载量和分享率。"""
html_text = self._prepare_html_text(html_text)
upload_match = re.search(r"[^总]上[传傳]量?[::_<>/a-zA-Z-=\"'\s#;]+([\d,.\s]+[KMGTPI]*B)", html_text,
@@ -142,10 +142,10 @@ class Unit3dSiteUserInfo(SiteParserBase):
self.ratio = text_tools.parse_float(ratio_match.group(1)) if (
ratio_match and ratio_match.group(1).strip()) else 0.0
def _parse_message_unread_links(self, html_text: str, msg_links: list) -> Optional[str]:
def _parse_message_unread_links(self, html_text: str, msg_links: list[str]) -> Optional[str]:
"""Unit3D 没有兼容的未读消息列表解析。"""
return None
def _parse_message_content(self, html_text):
def _parse_message_content(self, html_text: str) -> tuple[Optional[str], Optional[str], Optional[str]]:
"""Unit3D 没有兼容的未读消息正文解析。"""
return None, None, None