diff --git a/api/sonarr/client.py b/api/sonarr/client.py index 76003f9..649f1a9 100644 --- a/api/sonarr/client.py +++ b/api/sonarr/client.py @@ -13,24 +13,27 @@ def __init__(self, payload, discord_bot): self.check_request_type() def initialize_global_variables(self): - self.event_type = self.payload.get('eventType', 'N/A') - self.instance_name = self.payload.get('instanceName', 'N/A') - self.old_version = self.payload.get('previousVersion', 'N/A') - self.new_version = self.payload.get('newVersion', 'N/A') - self.series = self.payload.get('series', {}) - self.series_title = self.series.get('title', 'N/A') - self.release_data = self.payload.get('release', {}) - self.episodes = self.payload.get('episodes', {}) - self.tvdb_id = self.series.get('tvdbId', 'N/A') - self.quality = self.release_data.get('quality', 'N/A') - self.size = self.release_data.get('size', 'N/A') - self.indexer = self.release_data.get('indexer', 'N/A') - self.release_title = self.release_data.get('releaseTitle', 'N/A') - self.custom_format_score = self.release_data.get('customFormatScore', 'N/A') - self.custom_formats = self.release_data.get('customFormats', []) - self.episode_count = len(self.episodes) - if self.event_type != 'Test': - self.poster = TMDb.show_poster_path(self.tvdb_id) + try: + self.event_type = self.payload.get('eventType', 'N/A') + self.instance_name = self.payload.get('instanceName', 'N/A') + self.old_version = self.payload.get('previousVersion', 'N/A') + self.new_version = self.payload.get('newVersion', 'N/A') + self.series = self.payload.get('series', {}) + self.series_title = self.series.get('title', 'N/A') + self.release_data = self.payload.get('release', {}) + self.episodes = self.payload.get('episodes', []) + self.tvdb_id = self.series.get('tvdbId', 'N/A') + self.quality = self.release_data.get('quality', 'N/A') + self.size = self.release_data.get('size', 'N/A') + self.indexer = self.release_data.get('indexer', 'N/A') + self.release_title = self.release_data.get('releaseTitle', 'N/A') + self.custom_format_score = self.release_data.get('customFormatScore', 'N/A') + self.custom_formats = self.release_data.get('customFormats', []) + self.episode_count = len(self.episodes) + if self.event_type != 'Test' and self.tvdb_id != 'N/A': + self.poster = TMDb.show_poster_path(self.tvdb_id) + except Exception as e: + logger.error(f"Error initializing global variables: {e}") def check_request_type(self): if self.episode_count > 1: diff --git a/src/radarr/functions.py b/src/radarr/functions.py index e2db807..980481a 100644 --- a/src/radarr/functions.py +++ b/src/radarr/functions.py @@ -4,6 +4,8 @@ from utils.converter import Converter from config.globals import RADARR_ICON +from utils.custom_logger import logger + async def process_webhook(handler, channel): def build_grab_embed(): embed = EmbedBuilder(title=handler.embed_title, description=handler.release_title, color=0x9e7a18) @@ -11,6 +13,9 @@ def build_grab_embed(): embed.set_thumbnail(url=handler.poster) embed.set_author(name="A new grab by Radarr", icon_url=RADARR_ICON) embed.set_footer(text=f"{handler.quality} • {Converter.bytes_to_human_readable(handler.size)} • {handler.indexer}") + + logger.info(f"Sending grab embed to Discord: {handler.release_title} - {handler.embed_title}") + return embed def build_download_embed(): @@ -18,14 +23,20 @@ def build_download_embed(): return embed def build_application_update_embed(): - embed = EmbedBuilder(title=handler.embed_title) + embed = EmbedBuilder() embed.add_field(name="Old Version", value=handler.old_version, inline=True) embed.add_field(name="New Version", value=handler.new_version, inline=True) embed.set_author(name=f"{handler.instance_name} - {handler.event_type}", icon_url=RADARR_ICON) + + logger.info(f"Sending application update embed to Discord: {handler.instance_name} - {handler.event_type}") + return embed def build_test_embed(): embed = EmbedBuilder(description=f"This is a test event from {handler.instance_name}, it was a success!", color=0x9e7a18) + + logger.info(f"Sending test embed to Discord: {handler.instance_name}") + return embed embed_builders = { diff --git a/src/sonarr/functions.py b/src/sonarr/functions.py index 42a41c9..a762d8a 100644 --- a/src/sonarr/functions.py +++ b/src/sonarr/functions.py @@ -4,6 +4,8 @@ from utils.converter import Converter from config.globals import SONARR_ICON +from utils.custom_logger import logger + async def process_webhook(handler, channel): def build_grab_embed(): embed = EmbedBuilder(title=handler.embed_title, description=handler.release_title, color=0x9e7a18) @@ -11,6 +13,9 @@ def build_grab_embed(): embed.set_thumbnail(url=handler.poster) embed.set_author(name="A new grab by Sonarr", icon_url=SONARR_ICON) embed.set_footer(text=f"{handler.quality} • {Converter.bytes_to_human_readable(handler.size)} • {handler.indexer}") + + logger.info(f"Sending grab embed to Discord: {handler.release_title} - {handler.embed_title}") + return embed def build_download_embed(): @@ -18,14 +23,20 @@ def build_download_embed(): return embed def build_application_update_embed(): - embed = EmbedBuilder(title=handler.embed_title) + embed = EmbedBuilder() embed.add_field(name="Old Version", value=handler.old_version, inline=True) embed.add_field(name="New Version", value=handler.new_version, inline=True) embed.set_author(name=f"{handler.instance_name} - {handler.event_type}", icon_url=SONARR_ICON) + + logger.info(f"Sending application update embed to Discord: {handler.instance_name} - {handler.event_type}") + return embed def build_test_embed(): embed = EmbedBuilder(description=f"This is a test event from {handler.instance_name}, it was a success!", color=0xadd9c9) + + logger.info(f"Sending test embed to Discord: {handler.instance_name}") + return embed embed_builders = {