Skip to content

Commit 8f7ab97

Browse files
committed
Added ntfy tag and priority support to send_webhook
1 parent c87d6d4 commit 8f7ab97

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

spotify_monitor.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,7 +2566,7 @@ def build_ntfy_image(image_url: str = "") -> Optional[bytes]:
25662566

25672567

25682568
# Sends one webhook through an isolated bounded retry path that never uses Spotify retries
2569-
def send_webhook(title: str, description: str, notification_type: str = "song", force: bool = False, sleeper: Optional[Callable[[float], None]] = None, image_url: str = "") -> int:
2569+
def send_webhook(title: str, description: str, notification_type: str = "song", force: bool = False, sleeper: Optional[Callable[[float], None]] = None, image_url: str = "", ntfy_priority: int = 0, ntfy_tags: str = "") -> int:
25702570
if not force and not webhook_event_enabled(notification_type):
25712571
return 1
25722572
if not validate_webhook_url():
@@ -2589,11 +2589,17 @@ def send_webhook(title: str, description: str, notification_type: str = "song",
25892589
last_error: Any = None
25902590
for attempt in range(WEBHOOK_MAX_ATTEMPTS):
25912591
try:
2592+
ntfy_params = {"title": ntfy_title}
2593+
if ntfy_priority and isinstance(ntfy_priority, int):
2594+
ntfy_params["priority"] = ntfy_priority
2595+
if ntfy_tags and isinstance(ntfy_tags, str):
2596+
ntfy_params["tags"] = ntfy_tags
25922597
if provider == "ntfy":
25932598
if use_ntfy_image:
2594-
response = WEBHOOK_SESSION.post(str(WEBHOOK_URL).strip(), data=ntfy_image, params={"title": ntfy_title, "message": ntfy_message}, headers={**request_headers, "Content-Type": "image/jpeg", "X-Filename": NTFY_IMAGE_FILENAME}, timeout=WEBHOOK_TIMEOUT_SECONDS)
2599+
ntfy_params["message"] = ntfy_message.encode("utf-8")
2600+
response = WEBHOOK_SESSION.post(str(WEBHOOK_URL).strip(), data=ntfy_image, params=ntfy_params, headers={**request_headers, "Content-Type": "image/jpeg", "X-Filename": NTFY_IMAGE_FILENAME}, timeout=WEBHOOK_TIMEOUT_SECONDS)
25952601
else:
2596-
response = WEBHOOK_SESSION.post(str(WEBHOOK_URL).strip(), data=ntfy_message.encode("utf-8"), params={"title": ntfy_title}, headers=request_headers, timeout=WEBHOOK_TIMEOUT_SECONDS)
2602+
response = WEBHOOK_SESSION.post(str(WEBHOOK_URL).strip(), data=ntfy_message.encode("utf-8"), params=ntfy_params, headers=request_headers, timeout=WEBHOOK_TIMEOUT_SECONDS)
25972603
else:
25982604
response = WEBHOOK_SESSION.post(str(WEBHOOK_URL).strip(), json=discord_payload, headers=request_headers, timeout=WEBHOOK_TIMEOUT_SECONDS)
25992605
if 200 <= response.status_code <= 299:

0 commit comments

Comments
 (0)