Skip to content

Commit

Permalink
Merge pull request #21 from zeroquinc:radarr-title
Browse files Browse the repository at this point in the history
fix: remove N/A from Radarr update embed
  • Loading branch information
zeroquinc authored Jun 22, 2024
2 parents bb9eaed + 6970952 commit fef461c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
39 changes: 21 additions & 18 deletions api/sonarr/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion src/radarr/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@
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)
embed.add_field(name="Custom Formats", value=f"{Formatter.format_custom_formats(handler.custom_format_score, handler.custom_formats)}", inline=False)
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():
embed = EmbedBuilder(description="A download event has occurred.")
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 = {
Expand Down
13 changes: 12 additions & 1 deletion src/sonarr/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,39 @@
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)
embed.add_field(name="Custom Formats", value=f"{Formatter.format_custom_formats(handler.custom_format_score, handler.custom_formats)}", inline=False)
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():
embed = EmbedBuilder(description="A download event has occurred.")
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 = {
Expand Down

0 comments on commit fef461c

Please sign in to comment.