From ae3d8481e80e8cf1ccd5b08c053e932c4c0a28e4 Mon Sep 17 00:00:00 2001 From: dongho Date: Mon, 8 Dec 2025 12:53:52 +0000 Subject: [PATCH] update --- main.py | 58 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 9422cc6..a76ce57 100644 --- a/main.py +++ b/main.py @@ -58,9 +58,30 @@ async def send_notification(notification: Notification, background_tasks: Backgr try: # Format the message to include the service name # Plain text fallback - plain_message = f"[{notification.service_name}]\n{notification.content}" - # HTML message - html_message = f"[{notification.service_name}]
{notification.content}" + plain_message = f"[{notification.service_name}] {notification.content}" + + # HTML message with better formatting + # Map levels to emojis + level_emojis = { + "info": "â„šī¸", + "warning": "âš ī¸", + "error": "🚨", + "success": "✅" + } + emoji = level_emojis.get(notification.level, "đŸ“ĸ") + # Clean up content + cleaned_content = notification.content.replace("{album_explicit}", "") + + # Format the message to include the service name + # Plain text fallback + plain_message = f"[{notification.service_name}] {cleaned_content}" + + # HTML message with better formatting + + html_message = ( + f"

{emoji} {notification.service_name}

" + f"
{cleaned_content.replace(chr(10), '
')}
" + ) # We can send it in background to not block the API response logger.info(f"Queueing message for room_id: {notification.room_id or 'Default'}") @@ -82,27 +103,40 @@ async def receive_jellyfin_webhook(payload: JellyfinPayload, background_tasks: B return {"status": "ignored", "reason": "Not an ItemAdded event"} # content construction - content = "" + plain_content = "" + html_content = "" + if payload.item_type == "Movie": - content = f"New Movie: {payload.name}" + plain_content = f"New Movie: {payload.name}" + html_content = f"

đŸŽŦ New Movie Added

{payload.name}" + if payload.year: - content += f" ({payload.year})" + plain_content += f" ({payload.year})" + html_content += f" ({payload.year})" if payload.overview: - content += f"\n{payload.overview}" + plain_content += f"\n{payload.overview}" + html_content += f"
{payload.overview}
" + elif payload.item_type == "Episode": show = payload.series_name or "Unknown Series" s = f"S{payload.season:02d}" if payload.season is not None else "S??" e = f"E{payload.episode:02d}" if payload.episode is not None else "E??" - content = f"New Episode: {show} - {s}{e} - {payload.name}" + + plain_content = f"New Episode: {show} - {s}{e} - {payload.name}" + html_content = ( + f"

đŸ“ē New Episode Added

" + f"{show}
" + f"{s}{e} - {payload.name}" + ) else: # Fallback for Series, Season, etc. - content = f"New {payload.item_type}: {payload.name}" + plain_content = f"New {payload.item_type}: {payload.name}" + html_content = f"

✨ New {payload.item_type} Added

{payload.name}" - plain_message = f"[Jellyfin]\n{content}" - html_message = f"[Jellyfin]
{content.replace(chr(10), '
')}" + plain_message = f"[Jellyfin] {plain_content}" logger.info(f"Queueing Jellyfin message for room_id: {payload.room_id or 'Default'}") - background_tasks.add_task(bot.send_message, plain_message, html_message, payload.room_id) + background_tasks.add_task(bot.send_message, plain_message, html_content, payload.room_id) return {"status": "queued"} except Exception as e: