diff --git a/scene_search/index_jobs.py b/scene_search/index_jobs.py index bcffda1..e43033c 100644 --- a/scene_search/index_jobs.py +++ b/scene_search/index_jobs.py @@ -82,6 +82,30 @@ class IndexJobManager: ) return result + def apply_library_selection(self, library_ids: list[str]) -> dict[str, object]: + with self._state_lock: + if self._state.get("running"): + raise RuntimeError("A Jellyfin indexing job is already running.") + + selected_ids = { + str(value).strip() + for value in library_ids + if str(value).strip() + } + result = reconcile_selected_libraries(selected_ids) + removed_ids = [ + str(value) + for value in (result.get("removed_library_ids") or []) + ] + if removed_ids: + self.search_service.meili.delete_jellyfin_libraries(removed_ids) + print( + "Removed deselected Jellyfin libraries: " + + ", ".join(removed_ids) + + f" ({int(result.get('removed_media') or 0)} media item(s))" + ) + return result + def start(self, library_ids: list[str], *, force: bool = False) -> dict[str, Any]: with self._state_lock: if self._state.get("running"):