fix: 清掉清单里剩下的死代码、重复样式和评论解析

This commit is contained in:
2026-11-16 15:36:28 +08:00
parent 33640f7da8
commit 1cd7c7f818
12 changed files with 57 additions and 109 deletions
-48
View File
@@ -40,14 +40,6 @@ _config: dict[str, Any] = {
}
def reset_encrypt_config() -> None:
with _lock:
_config["path"] = DEFAULT_ENCRYPT_PATH
_config["js_url"] = DEFAULT_JS_URL
_config["loaded_at"] = 0.0
_config["retry_at"] = 0.0
def _script_host_allowed(url: str) -> bool:
parsed = urlparse(url)
if parsed.scheme != "https" or parsed.username or parsed.password:
@@ -159,15 +151,6 @@ def _note_fetch_failure() -> None:
_config["retry_at"] = time.time() + _FAIL_COOLDOWN
def refresh_encrypt_config(client: httpx.Client, origin: str, user_agent: str) -> None:
if not _stale():
return
with _fetch_guard:
if not _stale():
return
_fetch_js_config(client.get, origin, user_agent)
async def refresh_encrypt_config_async(
client: httpx.AsyncClient, origin: str, user_agent: str
) -> None:
@@ -186,23 +169,6 @@ async def refresh_encrypt_config_async(
_fetch_guard.release()
def _fetch_js_config(get, origin: str, user_agent: str) -> None:
url = _js_url(origin)
if not _script_host_allowed(url):
log.warning("播放脚本地址不在允许的主机上")
_note_fetch_failure()
return
try:
resp = get(url, headers={"User-Agent": user_agent, "Referer": origin.rstrip("/") + "/"})
if resp.status_code == 200 and resp.text:
_update_from_js(resp.text)
return
log.warning("读取播放脚本失败:HTTP %s", getattr(resp, "status_code", ""))
except Exception:
log.warning("读取播放脚本失败", exc_info=True)
_note_fetch_failure()
async def _fetch_js_config_async(
client: httpx.AsyncClient, origin: str, user_agent: str
) -> None:
@@ -267,13 +233,6 @@ def parse_encrypt_response(resp: httpx.Response) -> str:
raise RuntimeError(f"GetEncryptRequest 失败: {raw[:200]}")
def fetch_encryption(
client: httpx.Client, body_json: str, *, origin: str, user_agent: str
) -> str:
refresh_encrypt_config(client, origin, user_agent)
return _post_encryption(client.post, body_json, origin, user_agent)
async def fetch_encryption_async(
client: httpx.AsyncClient, body_json: str, *, origin: str, user_agent: str
) -> str:
@@ -281,13 +240,6 @@ async def fetch_encryption_async(
return await _post_encryption_async(client, body_json, origin, user_agent)
def _post_encryption(post, body_json: str, origin: str, user_agent: str) -> str:
url = encrypt_url(origin)
headers = encrypt_headers(origin, user_agent)
resp = post(url, content=encrypt_payload(body_json), headers=headers)
return parse_encrypt_response(resp)
async def _post_encryption_async(
client: httpx.AsyncClient, body_json: str, origin: str, user_agent: str
) -> str: