mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
fix(site): recognize Gazelle login state (#6464)
This commit is contained in:
@@ -12,8 +12,29 @@ from app.modules.indexer.parser import SiteParserBase, SiteSchema
|
|||||||
|
|
||||||
|
|
||||||
class GazelleSiteUserInfo(SiteParserBase):
|
class GazelleSiteUserInfo(SiteParserBase):
|
||||||
|
"""Gazelle 站点用户数据解析器。"""
|
||||||
|
|
||||||
schema = SiteSchema.Gazelle
|
schema = SiteSchema.Gazelle
|
||||||
|
|
||||||
|
def _parse_logged_in(self, html_text: str) -> bool:
|
||||||
|
"""
|
||||||
|
识别 Gazelle 登录态,兼容不展示退出入口的站点首页。
|
||||||
|
|
||||||
|
:param html_text: 站点首页 HTML
|
||||||
|
:return: 已登录返回 True,否则返回 False
|
||||||
|
"""
|
||||||
|
html = etree.HTML(html_text)
|
||||||
|
try:
|
||||||
|
if DomUtils.has_child_elements(html) and html.xpath(
|
||||||
|
'//a[contains(@href, "user.php?id=")]'
|
||||||
|
):
|
||||||
|
return True
|
||||||
|
finally:
|
||||||
|
if html is not None:
|
||||||
|
del html
|
||||||
|
|
||||||
|
return super()._parse_logged_in(html_text)
|
||||||
|
|
||||||
def _parse_user_base_info(self, html_text: str):
|
def _parse_user_base_info(self, html_text: str):
|
||||||
html_text = self._prepare_html_text(html_text)
|
html_text = self._prepare_html_text(html_text)
|
||||||
html = etree.HTML(html_text)
|
html = etree.HTML(html_text)
|
||||||
|
|||||||
@@ -179,3 +179,27 @@ def test_gazelle_seeding_keeps_legacy_column_fallback():
|
|||||||
assert parser.seeding == 1
|
assert parser.seeding == 1
|
||||||
assert parser.seeding_size == 2147483648
|
assert parser.seeding_size == 2147483648
|
||||||
assert parser.seeding_info == [[45, 2147483648]]
|
assert parser.seeding_info == [[45, 2147483648]]
|
||||||
|
|
||||||
|
|
||||||
|
def test_gazelle_login_accepts_current_user_link_without_logout_marker():
|
||||||
|
"""Gazelle 首页仅暴露当前用户链接时也应识别为已登录。"""
|
||||||
|
parser = _build_parser()
|
||||||
|
logged_in_html = (
|
||||||
|
'<html><body><a href="user.php?id=1234">tester</a>'
|
||||||
|
'<a href="bonus.php">积分 (42.0)</a></body></html>'
|
||||||
|
)
|
||||||
|
|
||||||
|
assert parser._parse_logged_in(logged_in_html) is True
|
||||||
|
assert parser.err_msg is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_gazelle_login_rejects_password_form_without_current_user_link():
|
||||||
|
"""Gazelle 登录页不得因普通用户相关文本被误判为已登录。"""
|
||||||
|
parser = _build_parser()
|
||||||
|
login_html = (
|
||||||
|
'<html><body><form action="login.php">'
|
||||||
|
'<input type="password" name="password"></form></body></html>'
|
||||||
|
)
|
||||||
|
|
||||||
|
assert parser._parse_logged_in(login_html) is False
|
||||||
|
assert parser.err_msg == "未检测到已登陆,请检查cookies是否过期"
|
||||||
|
|||||||
Reference in New Issue
Block a user