Notify completed downloads and finish watchlist entries
This commit is contained in:
+34
-1
@@ -19,7 +19,7 @@ from uuid import uuid4
|
||||
PROJECT_ROOT = Path(__file__).resolve().parent
|
||||
ANI_CLI = os.environ.get("ANI_CLI_BIN") or shutil.which("ani-cli") or "ani-cli"
|
||||
APP_NAME = "ani-cli-web"
|
||||
VERSION = "0.33.0"
|
||||
VERSION = "0.34.0"
|
||||
ALLANIME_BASE = "allanime.day"
|
||||
ALLANIME_API = f"https://api.{ALLANIME_BASE}"
|
||||
ALLANIME_REFERER = "https://allmanga.to"
|
||||
@@ -52,12 +52,14 @@ WATCHLIST_REFRESH_DELAY_DEFAULT_SECONDS = 5
|
||||
WATCHLIST_REFRESH_DELAY_MIN_SECONDS = 0
|
||||
WATCHLIST_REFRESH_DELAY_MAX_SECONDS = 300
|
||||
DISCORD_WEBHOOK_EVENT_CHOICES = (
|
||||
"download_completed",
|
||||
"watchlist_refresh_new_episodes",
|
||||
"watchlist_refresh_failed",
|
||||
"watchlist_refresh_interrupted",
|
||||
"runtime_error",
|
||||
)
|
||||
DISCORD_WEBHOOK_EVENT_LABELS = {
|
||||
"download_completed": "Download completed",
|
||||
"watchlist_refresh_new_episodes": "Refresh finished with new episodes found",
|
||||
"watchlist_refresh_failed": "Refresh failed or finished with refresh errors",
|
||||
"watchlist_refresh_interrupted": "Refresh interrupted by shutdown or restart",
|
||||
@@ -487,6 +489,37 @@ def send_discord_webhook_event(config, event_name, payload=None, force=False):
|
||||
_post_discord_webhook(webhook_url, request_payload, attachments=attachments)
|
||||
return {"sent": True, "event": event, "count": len(items)}
|
||||
|
||||
if event == "download_completed":
|
||||
title = str(payload.get("title") or payload.get("show_id") or "Unknown anime").strip()
|
||||
moved_files = payload.get("moved_files") if isinstance(payload.get("moved_files"), list) else []
|
||||
description_lines = []
|
||||
if payload.get("mode"):
|
||||
description_lines.append(f"Mode: {str(payload.get('mode')).strip()}")
|
||||
if payload.get("episodes"):
|
||||
description_lines.append(f"Episodes: {str(payload.get('episodes')).strip()}")
|
||||
if payload.get("category"):
|
||||
description_lines.append(f"Watchlist category: {str(payload.get('category')).strip()}")
|
||||
if moved_files:
|
||||
description_lines.append(f"Saved files: {len(moved_files)}")
|
||||
description_lines.extend(str(path).strip() for path in moved_files[:5] if str(path).strip())
|
||||
embed = {
|
||||
"title": title[:256],
|
||||
"description": "\n".join(description_lines)[:4096] or "Download completed.",
|
||||
"color": 5763719,
|
||||
}
|
||||
attachments = []
|
||||
thumb_path = thumbnail_file_path(payload.get("thumbnail_path"))
|
||||
if thumb_path and thumb_path.exists():
|
||||
attachment_name = f"download-thumb{thumb_path.suffix or '.jpg'}"
|
||||
attachments.append({"path": thumb_path, "filename": attachment_name})
|
||||
embed["thumbnail"] = {"url": f"attachment://{attachment_name}"}
|
||||
request_payload = {
|
||||
"content": "ani-cli-web finished a download.",
|
||||
"embeds": [embed],
|
||||
}
|
||||
_post_discord_webhook(webhook_url, request_payload, attachments=attachments)
|
||||
return {"sent": True, "event": event}
|
||||
|
||||
if event == "watchlist_refresh_failed":
|
||||
error_lines = []
|
||||
for item in (payload.get("items") if isinstance(payload.get("items"), list) else [])[:8]:
|
||||
|
||||
Reference in New Issue
Block a user