mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-17 07:21:28 +00:00
Add safe legacy Jellyfin thumbnail cleanup
This commit is contained in:
@@ -59,3 +59,71 @@ def remove_media_by_source(
|
||||
shutil.rmtree(thumbs_dir / item.media_id, ignore_errors=True)
|
||||
|
||||
return matches
|
||||
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class LegacyJellyfinThumbs:
|
||||
media_id: str
|
||||
title: str
|
||||
directory: Path
|
||||
files: int
|
||||
bytes: int
|
||||
|
||||
|
||||
def list_legacy_jellyfin_thumbs(
|
||||
db_path: Path,
|
||||
thumbs_dir: Path,
|
||||
) -> list[LegacyJellyfinThumbs]:
|
||||
"""List duplicated local thumbs for Jellyfin items backed by Trickplay."""
|
||||
init_db(db_path)
|
||||
with connect(db_path) as con:
|
||||
rows = con.execute(
|
||||
"""
|
||||
SELECT id, title
|
||||
FROM media
|
||||
WHERE source_kind = 'jellyfin'
|
||||
AND trickplay_width IS NOT NULL
|
||||
ORDER BY title, id
|
||||
"""
|
||||
).fetchall()
|
||||
|
||||
results: list[LegacyJellyfinThumbs] = []
|
||||
for row in rows:
|
||||
directory = thumbs_dir / str(row["id"])
|
||||
if not directory.is_dir():
|
||||
continue
|
||||
|
||||
files = 0
|
||||
size = 0
|
||||
for path in directory.rglob("*"):
|
||||
if not path.is_file():
|
||||
continue
|
||||
files += 1
|
||||
try:
|
||||
size += path.stat().st_size
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
results.append(
|
||||
LegacyJellyfinThumbs(
|
||||
media_id=str(row["id"]),
|
||||
title=str(row["title"]),
|
||||
directory=directory,
|
||||
files=files,
|
||||
bytes=size,
|
||||
)
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def remove_legacy_jellyfin_thumbs(
|
||||
db_path: Path,
|
||||
thumbs_dir: Path,
|
||||
) -> list[LegacyJellyfinThumbs]:
|
||||
"""Remove only duplicated Jellyfin JPEGs; canonical vectors remain untouched."""
|
||||
matches = list_legacy_jellyfin_thumbs(db_path, thumbs_dir)
|
||||
for item in matches:
|
||||
shutil.rmtree(item.directory, ignore_errors=True)
|
||||
return matches
|
||||
|
||||
Reference in New Issue
Block a user