Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(catalog): 厂牌官网全连不上时只挡一天

longmeidao3c0cd4d988ee
diff --git a/src/peach/studio_followup.py b/src/peach/studio_followup.py
index 930c395a7..32008595b 100644
--- a/src/peach/studio_followup.py
+++ b/src/peach/studio_followup.py
@@ -48,6 +48,9 @@ ICON_INTERVAL, ICON_TIMEOUT = 1.5, 20.0
#: 派出去过,`変態紳士倶楽部` 官网 09-23 登记后一直没图。没图的厂牌只有二三十家,几轮就轮遍。
STOCK_SHARE = 8
+#: 候选官网全都连不上时,过多久存量补派再派这一家。与补女优资料「未取得」的那一档同为一天。
+RETRY_UNREACHED = 24 * 3600
+
def followup_key(entity_id: int) -> str:
return f"{TASK_KEY}:{int(entity_id)}"
@@ -131,14 +134,17 @@ def run(contract, key: str, handle) -> dict:
人像闸取不到模型的那一次不记:结论取决于那天有没有网,记下来就要等到这家多一部
作品或多一条链接才会再试,活动中心「立即重试」取回模型之后也补不回来。
+ 候选官网一个都连不上的那次照记,但只保 `RETRY_UNREACHED`:同样是那天有没有网的事。
"""
summary = _run(contract, key, handle)
if summary.get("face_match_unavailable"):
return summary
with contract.database.read_connection() as connection:
current = fingerprint(connection, parse_key(key))
+ site = summary.get("site") or {}
Attempts(attempts_root(contract.candidate_root)).record(
- key, current, str(summary.get("outcome", "")))
+ key, current, str(summary.get("outcome", "")),
+ retry_after=RETRY_UNREACHED if site.get("unreached") else None)
return summary
@@ -180,8 +186,12 @@ def _land_site(contract, entity_id: int, name: str, aliases, batch: str) -> dict
verdict = str(row["verdict"])
if verdict != "ok":
# `weak` 与 `未取得` 都不写:前者要人看,后者是没有证据。
- return {"outcome": "待人确认" if verdict == "weak" else "未取得",
- "verdict": verdict, "note": str(row["note"])[:200]}
+ result = {"outcome": "待人确认" if verdict == "weak" else "未取得",
+ "verdict": verdict, "note": str(row["note"])[:200]}
+ # 试过候选却没有一个回了 HTTP 状态:全是传输层失败,多半是断网,不是这家没有官网。
+ if row.get("candidate_url") and not row.get("status"):
+ result["unreached"] = True
+ return result
url = str(row["final_url"] or row["candidate_url"])
now = datetime.now(timezone.utc).isoformat()
metadata = {"source": SOURCE, "batch": batch, "verdict": verdict, "installed_at": now,
diff --git a/tests/test_studio_followup.py b/tests/test_studio_followup.py
index ee517c74d..78003e822 100644
--- a/tests/test_studio_followup.py
+++ b/tests/test_studio_followup.py
@@ -171,6 +171,40 @@ class PlanTests(StudioFollowupCase):
studio_followup.stock(connection, self.logos, attempts, limit=10)]
self.assertEqual(planned, [studio_followup.followup_key(studio)])
+ def test_stock_tries_again_a_day_after_no_candidate_answered(self):
+ """候选官网全连不上(断网)只挡一天;回了 HTTP 状态的未取得照旧等实体变。"""
+ import time
+
+ from peach.followups import Attempts, attempts_root
+
+ studio = self.entity("studio", "OLDLABEL")
+ with self.database.write_transaction(notify=False) as connection:
+ connection.execute("INSERT INTO asset(id,location,path,name,medium,code,size)"
+ " VALUES(1,'R:','R:\\media\\a.mp4','a.mp4','video','OLD-1',1)")
+ connection.execute("INSERT INTO asset_entity(asset_id,entity_id,role,source)"
+ " VALUES(1,?,'studio','test')", (studio,))
+ key = studio_followup.followup_key(studio)
+
+ def planned(after: float) -> list[str]:
+ attempts = Attempts(attempts_root(self.contract.candidate_root),
+ clock=lambda: time.time() + after)
+ with self.database.read_connection() as connection:
+ return [item.key for item in
+ studio_followup.stock(connection, self.logos, attempts, limit=10)]
+
+ unreached = {**site_row("未取得"), "status": "", "note": "取不到:ConnectError"}
+ with mock.patch.object(studio_followup.studio_sites, "discover",
+ return_value=(unreached, 0.0)):
+ self.run_followup(studio)
+ self.assertEqual(planned(0), [])
+ self.assertEqual(planned(studio_followup.RETRY_UNREACHED + 60), [key])
+
+ answered = {**site_row("未取得"), "status": 404, "note": "HTTP 404"}
+ with mock.patch.object(studio_followup.studio_sites, "discover",
+ return_value=(answered, 0.0)):
+ self.run_followup(studio)
+ self.assertEqual(planned(studio_followup.RETRY_UNREACHED + 60), [])
+
def test_stock_studios_are_not_crowded_out_by_avatarless_performers(self):
"""没头像的女优再多,存量厂牌也有自己那一份名额。"""
from peach import (avatar_followup, library_processing, performer_alias_followup,