Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 换头像时同一番号的几份文件只占一格

longmeidaoa9458b16164c
diff --git a/src/peach/avatar_picker.py b/src/peach/avatar_picker.py
index c55bee567..86fe1e8bd 100644
--- a/src/peach/avatar_picker.py
+++ b/src/peach/avatar_picker.py
@@ -176,6 +176,9 @@ def asset_artwork(connection: sqlite3.Connection, cover_root: Path,
乘以十张图,摆出来是几百个格子,而人要找的是「哪一部里有一张正脸」。
没有封面也没铺过九宫格的作品不列:那种格子点开是一片空白。
+
+ 同一个番号分了几段、或在两个目录各有一份时,账本里是几条 asset 行,封面却是同一
+ 张:只留文件最大的那一份,其余几行不再各占一格。
"""
rows = connection.execute(
"SELECT a.id,a.code,COALESCE(NULLIF(a.catalog_title,''),a.name),a.snapshot_path "
@@ -185,10 +188,15 @@ def asset_artwork(connection: sqlite3.Connection, cover_root: Path,
(int(entity_id), MAX_ASSET_CHOICES * 3),
).fetchall()
out: list[Choice] = []
+ seen_codes: set[str] = set()
for asset_id, code, title, snapshot in rows:
if len(out) >= MAX_ASSET_CHOICES:
break
key = normalise_code_key(code)
+ if key:
+ if key in seen_codes:
+ continue
+ seen_codes.add(key)
has_cover = bool(key) and (Path(cover_root) / f"{key}.jpg").is_file()
has_sheet = bool(snapshot)
if not has_cover and not has_sheet:
diff --git a/tests/test_avatar_picker.py b/tests/test_avatar_picker.py
index 63fbcc516..0742863c3 100644
--- a/tests/test_avatar_picker.py
+++ b/tests/test_avatar_picker.py
@@ -329,12 +329,13 @@ class AssetArtworkTests(PickerFixture):
frame=lambda asset_id, cell: self.cell if cell == 4 else None)
def add_asset(self, asset_id: int, code: str, snapshot: str = "sheet.jpg",
- entity_id: int = 7792, size: int = 100) -> None:
+ entity_id: int = 7792, size: int = 100, file: str = "") -> None:
+ file = file or f"{code}.mp4"
with self.connection:
self.connection.execute(
"INSERT INTO asset(id,location,path,name,medium,code,catalog_title,"
"size,snapshot_path) VALUES(?,'R:',?,?,'video',?,?,?,?)",
- (asset_id, f"R:\\media\\{code}.mp4", f"{code}.mp4", code,
+ (asset_id, f"R:\\media\\{file}", file, code,
f"{code} 的标题", size, snapshot))
self.connection.execute(
"INSERT INTO asset_entity(asset_id,entity_id,role,source) "
@@ -352,6 +353,16 @@ class AssetArtworkTests(PickerFixture):
["asset:11:cover"] + [f"asset:11:cell{n}" for n in range(9)])
self.assertTrue(assets[0]["crop"], "作品画面要先框一块才能当头像")
+ def test_one_code_split_over_several_files_still_takes_one_cell(self):
+ # 分段与重复目录各是一条 asset 行,封面同一张;留最大那份,格子只占一个。
+ self.add_asset(11, "ABW-232", size=100, file="ABW-232-1.mp4")
+ self.add_asset(12, "ABW-232", size=300, file="ABW-232-2.mp4")
+ self.add_asset(13, "abw232", size=200, file="dup\\abw232.mp4")
+ listed = avatar_picker.choices(self.connection, self.providers, self.avatars,
+ "performer", 7792, cover_root=self.covers)
+ assets = [one for one in listed["choices"] if one["source"] == "asset"]
+ self.assertEqual([one["ref"] for one in assets], ["asset:12:cover"])
+
def test_a_work_with_neither_a_cover_nor_a_sheet_is_not_listed(self):
self.add_asset(12, "NOPE-001", snapshot="")
listed = avatar_picker.choices(self.connection, self.providers, self.avatars,