Skip to content

Commit

Permalink
Merge pull request #31 from zeroquinc:format-hours-minutes
Browse files Browse the repository at this point in the history
fix: format hours and formats which tautulli doesnt support
  • Loading branch information
zeroquinc authored Oct 30, 2024
2 parents 64af27b + 7f8c9e2 commit e0f43b3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions api/plex/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json

from config.globals import PLEX_ICON, PLEX_PLAYING, PLEX_CONTENT
from src.discord.embed import EmbedBuilder
from utils.custom_logger import logger
Expand Down Expand Up @@ -31,6 +30,16 @@ def extract_details(self):
field_value = server_info.get(field)
setattr(self, field, field_value)

def format_duration_time(self):
if self.duration_time and self.duration_time != 'N/A':
try:
hours, minutes = self.duration_time.split(":")
return f"{int(hours):02}h {int(minutes):02}m"
except ValueError:
logger.error(f"Invalid duration_time format: {self.duration_time}")
return self.duration_time
return 'N/A'

async def handle_webhook(self):
logger.info(f"Processing Plex webhook payload for event type: {self.webhook_type}")
logger.debug(f"Payload: {json.dumps(self.payload, indent=4)}")
Expand Down Expand Up @@ -89,7 +98,7 @@ def embed_for_newcontent(self, color):
embed.add_field(name="Episodes", value=f"{self.episode_count}", inline=False)
elif self.webhook_type == 'newcontent_movie':
embed.add_field(name="Links", value=f"[IMDb]({self.imdb_url}) • [Trakt]({self.trakt_url})")
embed.set_footer(text=f"{self.genres}{self.duration_time}")
embed.set_footer(text=f"{self.genres}{self.format_duration_time()}")
embed.set_author(name=f"New {self.media_type.capitalize()} added to Plex", icon_url=PLEX_ICON)
return embed

Expand Down

0 comments on commit e0f43b3

Please sign in to comment.