Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: format hours and formats which tautulli doesnt support #31

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading