feat(snapshot): refresh API video metadata; keep removed visible
入库 / 小时近新片 / 全量快照成功时以 view_detail 覆盖 title、duration、 pages、cover、bvid、up_*、pubdate 等接口字段,并照旧写七项快照。 原站失效仅标 removed,不删行、不空写元数据;列表与详情继续展示, 快照队列仍跳过 removed。
This commit is contained in:
1 parent
99b71c037c
commit
6c73904b25
8 files changed
+329
-34
No files matched your search
@@ -410,6 +410,75 @@ class Repository:
|
||||
return [dict(row) for row in rows]
|
||||
return self.db.read(run)
|
||||
|
||||
def refresh_video_metadata(
|
||||
self,
|
||||
*,
|
||||
aid: int,
|
||||
bvid: str | None,
|
||||
title: str,
|
||||
up_mid: int | None,
|
||||
up_name: str | None,
|
||||
pubdate: int,
|
||||
duration: int | None = None,
|
||||
pages: int | None = None,
|
||||
cover: str | None = None,
|
||||
up_face: str | None = None,
|
||||
now: int | None = None,
|
||||
) -> bool:
|
||||
"""用接口返回字段覆盖更新已有视频元数据;不改 status,空值不冲掉旧值。
|
||||
|
||||
入库与快照成功路径共用。视频不存在时返回 False。
|
||||
"""
|
||||
now = self._now() if now is None else int(now)
|
||||
aid = int(aid)
|
||||
|
||||
def run(conn: sqlite3.Connection) -> bool:
|
||||
existing = conn.execute(
|
||||
"SELECT aid FROM video WHERE aid = ?", (aid,)
|
||||
).fetchone()
|
||||
if existing is None:
|
||||
return False
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE video SET
|
||||
bvid = COALESCE(?, bvid),
|
||||
title = CASE
|
||||
WHEN ? != '' THEN ?
|
||||
ELSE title
|
||||
END,
|
||||
up_mid = COALESCE(?, up_mid),
|
||||
up_name = COALESCE(?, up_name),
|
||||
pubdate = CASE
|
||||
WHEN ? > 0 THEN ?
|
||||
ELSE pubdate
|
||||
END,
|
||||
duration = COALESCE(?, duration),
|
||||
pages = COALESCE(?, pages),
|
||||
cover = COALESCE(?, cover),
|
||||
up_face = COALESCE(?, up_face),
|
||||
last_sync = ?
|
||||
WHERE aid = ?
|
||||
""",
|
||||
(
|
||||
bvid,
|
||||
title or "",
|
||||
title or "(无标题)",
|
||||
up_mid,
|
||||
up_name,
|
||||
int(pubdate or 0),
|
||||
int(pubdate or 0),
|
||||
None if duration is None else int(duration),
|
||||
None if pages is None else int(pages),
|
||||
cover,
|
||||
up_face,
|
||||
now,
|
||||
aid,
|
||||
),
|
||||
)
|
||||
return True
|
||||
|
||||
return self.db.write(run)
|
||||
|
||||
def ingest_video(
|
||||
self,
|
||||
*,
|
||||
@@ -430,6 +499,7 @@ class Repository:
|
||||
|
||||
不写 B 站收藏夹、不设置 ``folder_id``;同时删除同 aid 的候选行。
|
||||
既有的 ``removed`` / ``dropped`` / ``unfaved`` 状态都会被重新激活。
|
||||
已存在时仍以本次接口字段为准刷新元数据。
|
||||
"""
|
||||
now = self._now() if now is None else int(now)
|
||||
aid = int(aid)
|
||||
|
||||
Reference in new issue
Block a user