feat(p1): add daily snapshots and fan tracking
Implement P1: seven-metric view snapshots, relation/stat fan snapshots, failure placeholders, resume by daily completion markers, Cookie login warnings, daily SQLite backups, Shanghai daily scheduling, and CLI snapshot/auth-check commands. Real read-only run captured 795/795 videos successfully over 1124s with a verified daily backup.
This commit is contained in:
1 parent
ee289bfa56
commit
5c2ab7b187
20 files changed
+1680
-54
No files matched your search
@@ -85,3 +85,83 @@ class InfosResult:
|
||||
requested: tuple[int, ...]
|
||||
items: dict[int, FavResource]
|
||||
missing: tuple[int, ...]
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ViewStat:
|
||||
"""``x/web-interface/view`` 的七项统计。"""
|
||||
|
||||
aid: int
|
||||
bvid: str | None
|
||||
title: str
|
||||
view: int
|
||||
like: int
|
||||
favorite: int
|
||||
coin: int
|
||||
share: int
|
||||
reply: int
|
||||
danmaku: int
|
||||
|
||||
def metrics(self) -> dict[str, int]:
|
||||
return {
|
||||
"view": self.view,
|
||||
"like": self.like,
|
||||
"favorite": self.favorite,
|
||||
"coin": self.coin,
|
||||
"share": self.share,
|
||||
"reply": self.reply,
|
||||
"danmaku": self.danmaku,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_api(cls, item: Mapping[str, Any]) -> "ViewStat":
|
||||
aid = item.get("aid")
|
||||
if isinstance(aid, bool) or not isinstance(aid, int):
|
||||
raise ValueError("view data.aid 不是整数")
|
||||
stat = item.get("stat")
|
||||
if not isinstance(stat, Mapping):
|
||||
raise ValueError("view data.stat 不是对象")
|
||||
metrics: dict[str, int] = {}
|
||||
for key in ("view", "like", "favorite", "coin", "share", "reply", "danmaku"):
|
||||
value = stat.get(key)
|
||||
if isinstance(value, bool) or not isinstance(value, int) or value < 0:
|
||||
raise ValueError(f"view stat.{key} 不是非负整数")
|
||||
metrics[key] = value
|
||||
bvid = item.get("bvid")
|
||||
if not isinstance(bvid, str) or not bvid:
|
||||
bvid = None
|
||||
return cls(
|
||||
aid=aid,
|
||||
bvid=bvid,
|
||||
title=str(item.get("title") or ""),
|
||||
**metrics,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FanStat:
|
||||
mid: int
|
||||
follower: int
|
||||
following: int
|
||||
|
||||
@classmethod
|
||||
def from_api(cls, item: Mapping[str, Any]) -> "FanStat":
|
||||
mid = item.get("mid")
|
||||
follower = item.get("follower")
|
||||
following = item.get("following", 0)
|
||||
if isinstance(mid, bool) or not isinstance(mid, int):
|
||||
raise ValueError("relation/stat data.mid 不是整数")
|
||||
if isinstance(follower, bool) or not isinstance(follower, int) or follower < 0:
|
||||
raise ValueError("relation/stat data.follower 不是非负整数")
|
||||
if isinstance(following, bool) or not isinstance(following, int) or following < 0:
|
||||
raise ValueError("relation/stat data.following 不是非负整数")
|
||||
return cls(mid=mid, follower=follower, following=following)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LoginState:
|
||||
is_login: bool
|
||||
mid: int | None
|
||||
uname: str | None
|
||||
code: int
|
||||
message: str
|
||||
Reference in new issue
Block a user