feat(web): up avatars, follower count, and dedupe views/avg secondary

This commit is contained in:
kairee committed 2026-11-01 14:34:23 +08:00
1 parent 1ed3746f4b
commit 2ff3e7952b
23 files changed
+209 -58

No files matched your search

+26 -15
View File
@@ -97,7 +97,7 @@ class InfosResult:
@dataclass(frozen=True)
class ViewStat:
"""``x/web-interface/view`` 的七项统计。"""
"""``x/web-interface/view`` 的七项统计(含 UP 元数据)。"""
aid: int
bvid: str | None
@@ -109,6 +109,9 @@ class ViewStat:
share: int
reply: int
danmaku: int
up_mid: int | None = None
up_name: str | None = None
up_face: str | None = None
def metrics(self) -> dict[str, int]:
return {
@@ -138,10 +141,28 @@ class ViewStat:
bvid = item.get("bvid")
if not isinstance(bvid, str) or not bvid:
bvid = None
owner = item.get("owner") or {}
if not isinstance(owner, Mapping):
owner = {}
raw_mid = owner.get("mid")
up_mid = (
raw_mid
if isinstance(raw_mid, int) and not isinstance(raw_mid, bool)
else None
)
up_name = owner.get("name")
if not isinstance(up_name, str) or not up_name:
up_name = None
up_face = owner.get("face")
if not isinstance(up_face, str) or not up_face:
up_face = None
return cls(
aid=aid,
bvid=bvid,
title=str(item.get("title") or ""),
up_mid=up_mid,
up_name=up_name,
up_face=up_face,
**metrics,
)
@@ -163,6 +184,7 @@ class VideoDetail:
pages: int | None
cover: str | None
stat: ViewStat
up_face: str | None = None
def metrics(self) -> dict[str, int]:
return self.stat.metrics()
@@ -170,18 +192,6 @@ class VideoDetail:
@classmethod
def from_api(cls, item: Mapping[str, Any]) -> "VideoDetail":
stat = ViewStat.from_api(item)
owner = item.get("owner") or {}
if not isinstance(owner, Mapping):
owner = {}
raw_mid = owner.get("mid")
up_mid = (
raw_mid
if isinstance(raw_mid, int) and not isinstance(raw_mid, bool)
else None
)
up_name = owner.get("name")
if not isinstance(up_name, str) or not up_name:
up_name = None
raw_duration = item.get("duration")
duration = (
@@ -219,13 +229,14 @@ class VideoDetail:
aid=stat.aid,
bvid=stat.bvid,
title=stat.title,
up_mid=up_mid,
up_name=up_name,
up_mid=stat.up_mid,
up_name=stat.up_name,
pubdate=pubdate,
duration=duration,
pages=pages,
cover=cover,
stat=stat,
up_face=stat.up_face,
)