Expand Discord download and Jellyfin notifications
This commit is contained in:
@@ -997,6 +997,8 @@ def move_watchlist_item_to_jellyfin(item, config):
|
||||
except OSError:
|
||||
pass
|
||||
if not source_dir.exists():
|
||||
if target_dir.exists():
|
||||
return {"moved": False, "reason": "already_moved", "item": item, "source": str(source_dir), "target": str(target_dir)}
|
||||
return {"moved": False, "reason": "source_missing", "item": item, "source": str(source_dir), "target": str(target_dir)}
|
||||
target_dir.parent.mkdir(parents=True, exist_ok=True)
|
||||
if not target_dir.exists():
|
||||
@@ -1014,6 +1016,29 @@ def move_watchlist_item_to_jellyfin(item, config):
|
||||
}
|
||||
|
||||
|
||||
def notify_jellyfin_sync_result(item, result, config, automatic=False):
|
||||
reason = str(result.get("reason") or "").strip()
|
||||
if result.get("moved"):
|
||||
event_name = "jellyfin_sync_success"
|
||||
elif reason in {"already_moved", "same_path", "disabled", "not_downloaded", "category", "expected_count", "airing_status", "episodes_missing", "ready"}:
|
||||
return {"sent": False, "reason": "skip"}
|
||||
else:
|
||||
event_name = "jellyfin_sync_failed"
|
||||
payload = {
|
||||
"show_id": item.get("show_id"),
|
||||
"title": item.get("title"),
|
||||
"media_type": normalize_media_type(item.get("media_type")),
|
||||
"source": "automatic" if automatic else "manual",
|
||||
"reason": reason or ("moved" if result.get("moved") else "unknown"),
|
||||
"target": result.get("target"),
|
||||
"source_path": result.get("source"),
|
||||
"moved_files": result.get("moved_files") if isinstance(result.get("moved_files"), list) else [],
|
||||
"error": result.get("error"),
|
||||
}
|
||||
send_discord_webhook_event(config or get_config_snapshot(), event_name, payload)
|
||||
return {"sent": True, "event": event_name}
|
||||
|
||||
|
||||
def episode_specs_for_values(values, available_episodes):
|
||||
ordered = [str(value).strip() for value in available_episodes or [] if str(value).strip()]
|
||||
targets = {str(value).strip() for value in values or [] if str(value).strip()}
|
||||
@@ -2354,8 +2379,27 @@ def trigger_jellyfin_sync_for_item(item, automatic=False, config=None):
|
||||
media_type = normalize_media_type(item.get("media_type"))
|
||||
target_key = "jellyfin_movie_dir" if media_type == "movie" else "jellyfin_tv_dir"
|
||||
if not str(active_config.get(target_key) or "").strip():
|
||||
return {"moved": False, "reason": "target_missing", "item": item}
|
||||
result = move_watchlist_item_to_jellyfin(item, active_config)
|
||||
result = {"moved": False, "reason": "target_missing", "item": item}
|
||||
try:
|
||||
notify_jellyfin_sync_result(item, result, active_config, automatic=automatic)
|
||||
except Exception as exc:
|
||||
debug_log("discord_webhook.jellyfin_sync_failed", show_id=item.get("show_id"), reason=result.get("reason"), error=exc)
|
||||
return result
|
||||
try:
|
||||
result = move_watchlist_item_to_jellyfin(item, active_config)
|
||||
except Exception as exc:
|
||||
result = {
|
||||
"moved": False,
|
||||
"reason": "error",
|
||||
"item": item,
|
||||
"source": str(watchlist_source_library_dir(item, active_config)),
|
||||
"target": str(jellyfin_target_library_dir(item, active_config)),
|
||||
"error": str(exc),
|
||||
}
|
||||
try:
|
||||
notify_jellyfin_sync_result(item, result, active_config, automatic=automatic)
|
||||
except Exception as exc:
|
||||
debug_log("discord_webhook.jellyfin_sync_failed", show_id=item.get("show_id"), reason=result.get("reason"), error=exc)
|
||||
if result.get("moved"):
|
||||
debug_log(
|
||||
"jellyfin.sync.moved",
|
||||
|
||||
Reference in New Issue
Block a user