fix: 清掉清单里剩下的死代码、重复样式和评论解析
This commit is contained in:
@@ -655,7 +655,6 @@ def parse_course_page(page: str) -> dict:
|
||||
kind = re.search(r'class="(Knowledge_[A-Za-z]+)"', row)
|
||||
contributor = re.search(r"title='([^']*)'[^>]*href=\"/myhome\.htm", row)
|
||||
numbers = re.findall(r'<td class="textcenter"\s*>\s*<span class="color5">([^<]*)</span>', row)
|
||||
comments = re.search(r"<label>\((\d+)\)</label>", row)
|
||||
courses.append({
|
||||
"path": link.group(1),
|
||||
"title": unescape(link.group(2)).strip(),
|
||||
@@ -665,7 +664,6 @@ def parse_course_page(page: str) -> dict:
|
||||
"learners": numbers[1].strip() if len(numbers) > 1 else "",
|
||||
"released_on": numbers[2].strip() if len(numbers) > 2 else "",
|
||||
"updated_on": numbers[3].strip() if len(numbers) > 3 else "",
|
||||
"comments": comments.group(1) if comments else "",
|
||||
})
|
||||
return {
|
||||
"courses": courses,
|
||||
|
||||
@@ -113,7 +113,6 @@ def course_page(db: Session, query: str, offset: int, limit: int, kind: str = ""
|
||||
"learners": row.learners,
|
||||
"released_on": row.released_on,
|
||||
"updated_on": row.updated_on,
|
||||
"comments": row.comments,
|
||||
}
|
||||
for row in rows
|
||||
],
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -49,7 +49,6 @@ _STATUS = {STATUS_ALIVE: "可用", STATUS_DEAD: "失效", STATUS_NEW: "待检测
|
||||
_assign_lock = threading.Lock()
|
||||
_holds: dict[str, int] = {}
|
||||
_refresh_lock = threading.Lock()
|
||||
_stop: threading.Event | None = None
|
||||
_probe_guard = threading.Lock()
|
||||
_probe_state = {"running": False, "count": 0, "error": ""}
|
||||
|
||||
@@ -680,10 +679,8 @@ def _reset_pool_running() -> None:
|
||||
|
||||
|
||||
def start_proxy_pool() -> threading.Event:
|
||||
global _stop
|
||||
_reset_pool_running()
|
||||
stop = threading.Event()
|
||||
_stop = stop
|
||||
|
||||
def loop() -> None:
|
||||
if stop.wait(8):
|
||||
|
||||
Reference in New Issue
Block a user