Add remove command for indexed source kinds

This commit is contained in:
Sleeps
2026-10-06 16:22:38 +01:00
parent ff0fc25d78
commit 0b17f95414
+60
View File
@@ -26,6 +26,7 @@ from .jellyfin_index import (
cmd_jellyfin_libraries,
cmd_jellyfin_test,
)
from .maintenance import list_media_by_source, remove_media_by_source
from .meili import Meili
from .routing import ExplicitContentRouter, apply_context_routing
@@ -556,6 +557,51 @@ def cmd_caption(args: argparse.Namespace) -> None:
print("Next: python -m scene_search.cli sync-meili")
def cmd_remove(args: argparse.Namespace) -> None:
source_kind = args.source.strip().lower()
matches = list_media_by_source(settings.db_path, source_kind)
if not matches:
print(f"No media found with source_kind={source_kind!r}.")
return
print(f"Media matching source_kind={source_kind!r}:")
for item in matches:
print(f"- {item.title} ({item.media_id})")
if not args.yes:
answer = input(
f"Remove {len(matches)} media item(s), their frames/captions/vectors, "
"and cached thumbnails? [y/N] "
).strip().lower()
if answer not in {"y", "yes"}:
print("Cancelled.")
return
removed = remove_media_by_source(
settings.db_path,
settings.thumbs_dir,
source_kind,
)
print(f"Removed {len(removed)} media item(s) from the canonical index.")
with connect(settings.db_path) as con:
remaining = int(con.execute("SELECT COUNT(*) FROM media").fetchone()[0])
if remaining:
print("Rebuilding Meilisearch from remaining canonical media...")
cmd_sync_meili(args)
else:
print("No canonical media remain; clearing Meilisearch.")
meili = Meili(
settings.meili_url,
settings.meili_master_key,
settings.meili_index,
)
meili.clear_documents()
print("Meilisearch cleared.")
def cmd_status(_: argparse.Namespace) -> None:
init_db(settings.db_path)
@@ -736,6 +782,20 @@ def make_parser() -> argparse.ArgumentParser:
caption.add_argument("--sync", action="store_true", help="Sync captions to Meilisearch when finished")
caption.set_defaults(func=cmd_caption)
remove = sub.add_parser("remove", help="Remove indexed media by source kind")
remove.add_argument(
"--source",
required=True,
choices=["file", "jellyfin"],
help="Source kind to remove",
)
remove.add_argument(
"--yes",
action="store_true",
help="Skip the interactive confirmation prompt",
)
remove.set_defaults(func=cmd_remove)
status = sub.add_parser("status", help="Show canonical SQLite and Meilisearch index status")
status.set_defaults(func=cmd_status)