type: 收窄虎牙 OCR 与登录类型

This commit is contained in:
yml2213
2026-08-30 20:24:25 +08:00
parent cbd314f4e5
commit 92dc461e52
4 changed files with 324 additions and 214 deletions
+13 -3
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
from collections.abc import Iterable, Mapping
import requests
from requests.cookies import RequestsCookieJar
def cookie_pairs(cookie: str) -> list[tuple[str, str]]:
@@ -36,16 +37,25 @@ def normalize_cookie_pairs(pairs: Iterable[tuple[str, str]]) -> str:
return "; ".join(f"{key}={values[key]}" for key in ordered_keys)
def normalize_huya_cookie(cookie: str | Mapping[str, str] | requests.cookies.RequestsCookieJar | None) -> str:
def normalize_huya_cookie(
cookie: str | Mapping[str, str] | RequestsCookieJar | None,
) -> str:
"""把 Cookie 字符串、dict 或 CookieJar 转成去重后的浏览器 Cookie 字符串。"""
if not cookie:
return ""
if isinstance(cookie, str):
return normalize_cookie_pairs(cookie_pairs(cookie))
return normalize_cookie_pairs(cookie.items())
return normalize_cookie_pairs(
[
(str(key), "" if value is None else str(value))
for key, value in cookie.items()
]
)
def cookie_value(cookie: str | Mapping[str, str] | requests.cookies.RequestsCookieJar | None, key: str) -> str:
def cookie_value(
cookie: str | Mapping[str, str] | RequestsCookieJar | None, key: str
) -> str:
"""从 Cookie 中读取 key;有重复时以最后一次出现为准。"""
if not cookie or not key:
return ""