mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-14 22:11:27 +00:00
Track overall indexing progress
This commit is contained in:
@@ -88,6 +88,11 @@ class IndexJobManager:
|
||||
|
||||
client = build_jellyfin_client()
|
||||
libraries = resolve_library_ids(client, library_ids)
|
||||
library_item_totals = [
|
||||
client.item_count(str(item.get("Id") or ""))
|
||||
for item in libraries
|
||||
]
|
||||
overall_items_total = sum(library_item_totals)
|
||||
|
||||
with self._state_lock:
|
||||
self._state = {
|
||||
@@ -98,6 +103,10 @@ class IndexJobManager:
|
||||
"error": None,
|
||||
"library_total": len(libraries),
|
||||
"library_ids": [str(item.get("Id") or "") for item in libraries],
|
||||
"library_item_totals": library_item_totals,
|
||||
"overall_items_total": overall_items_total,
|
||||
"overall_items_completed": 0,
|
||||
"overall_percent": 0.0,
|
||||
}
|
||||
|
||||
self._thread = threading.Thread(
|
||||
@@ -112,6 +121,47 @@ class IndexJobManager:
|
||||
def _progress(self, update: dict) -> None:
|
||||
with self._state_lock:
|
||||
self._state.update(update)
|
||||
self._update_overall_progress_locked()
|
||||
|
||||
def _update_overall_progress_locked(self) -> None:
|
||||
stage = str(self._state.get("stage") or "")
|
||||
total = int(self._state.get("overall_items_total") or 0)
|
||||
totals = [
|
||||
int(value)
|
||||
for value in (self._state.get("library_item_totals") or [])
|
||||
]
|
||||
|
||||
if stage == "complete":
|
||||
self._state["overall_items_completed"] = total
|
||||
self._state["overall_percent"] = 100.0
|
||||
return
|
||||
|
||||
if stage in {"indexed", "syncing", "sync", "synced"}:
|
||||
self._state["overall_items_completed"] = total
|
||||
self._state["overall_percent"] = 99.0 if total else 99.0
|
||||
return
|
||||
|
||||
library_number = int(self._state.get("library_number") or 1)
|
||||
library_index = max(0, min(library_number - 1, len(totals)))
|
||||
before_library = sum(totals[:library_index])
|
||||
|
||||
item_number = int(self._state.get("item_number") or 0)
|
||||
completed_before_item = max(item_number - 1, 0)
|
||||
completed = min(before_library + completed_before_item, total)
|
||||
|
||||
fractional_item = 0.0
|
||||
frames_total = int(self._state.get("frames_total") or 0)
|
||||
frames_processed = int(self._state.get("frames_processed") or 0)
|
||||
if stage == "embedding" and frames_total > 0:
|
||||
fractional_item = min(max(frames_processed / frames_total, 0.0), 1.0)
|
||||
|
||||
position = min(completed + fractional_item, float(total))
|
||||
self._state["overall_items_completed"] = completed
|
||||
self._state["overall_percent"] = (
|
||||
round((position / total) * 99.0, 1)
|
||||
if total > 0
|
||||
else 0.0
|
||||
)
|
||||
|
||||
def _run(self, libraries: list[dict], force: bool) -> None:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user