diff --git a/jellyfin/api_client.py b/jellyfin/api_client.py index c7e73ca..2b73460 100644 --- a/jellyfin/api_client.py +++ b/jellyfin/api_client.py @@ -1,7 +1,12 @@ from settings import settings from jellyfin_apiclient_python import JellyfinClient -from jellyfin.models import JellyfinMediaItem, JellyfinMediaType, JellyfinMusicMediaMetadata, JellyfinMovieMediaMetadata, JellyfinEpisodeMediaMetadata -from jellyfin.utils import JellyfinUtils +from jellyfin.models import ( + JellyfinMediaItem, + JellyfinMediaType, + JellyfinMusicMediaMetadata, + JellyfinMovieMediaMetadata, + JellyfinEpisodeMediaMetadata) +from jellyfin.utils.config import configure_client from datetime import datetime from typing import Optional, Tuple import logging @@ -26,7 +31,7 @@ class JellyfinApiClient: self.logger.info("Connecting to Jellyfin server...") self.client = JellyfinClient() - JellyfinUtils.configure_client(self.client) + configure_client(self.client) self.authenticate() self.logger.info("Connected to Jellyfin server.") @@ -201,20 +206,22 @@ class JellyfinApiClient: media_id = item.get('Id') parent = self.client.jellyfin.get_item(item.get('ParentId')) parent_id = parent.get('ParentId') + series_name = item.get('SeriesName') season_number = item.get('ParentIndexNumber') episode_number = item.get('IndexNumber') + name = f"{series_name} S{season_number:02}E{episode_number:02}" + metadata = JellyfinEpisodeMediaMetadata( - subtitle=f"S{ - season_number:02}E{ - episode_number:02} of {series_name}") + subtitle=item.get('Name') + ) (start, end) = self.get_playback_info(item) return JellyfinMediaItem( id=media_id, - name=item.get('Name'), + name=name, type=JellyfinMediaType.EPISODE, image_url=self.get_image_url(parent_id), start=start, diff --git a/jellyfin/utils.py b/jellyfin/utils.py deleted file mode 100644 index 29a2e34..0000000 --- a/jellyfin/utils.py +++ /dev/null @@ -1,37 +0,0 @@ -from jellyfin_apiclient_python import JellyfinClient -from getmac import get_mac_address -from settings import settings -import os - - -class JellyfinUtils: - @staticmethod - def configure_client(client: JellyfinClient): - client.config.app( - settings.app_name, - settings.app_version, - JellyfinUtils.get_machine_name(), - JellyfinUtils.get_unique_id() - ) - client.config.data['auth.ssl'] = settings.jellyfin_server_url.startswith( - 'https://') - - @staticmethod - def get_machine_name() -> str: - """ - Retrieves the machine name of the current host. - - Returns: - str: The machine name. - """ - return os.uname().nodename - - @staticmethod - def get_unique_id() -> str: - """ - Retrieves the MAC address of the localhost as a unique identifier. - - Returns: - str: The MAC address. - """ - return get_mac_address(hostname="localhost") diff --git a/jellyfin/utils/config.py b/jellyfin/utils/config.py new file mode 100644 index 0000000..6398aea --- /dev/null +++ b/jellyfin/utils/config.py @@ -0,0 +1,41 @@ +from jellyfin_apiclient_python import JellyfinClient +from getmac import get_mac_address +from settings import settings +import os + + +def configure_client(client: JellyfinClient): + """ + Configures the Jellyfin client with application details and SSL settings. + + Args: + client (JellyfinClient): The Jellyfin client to configure. + """ + client.config.app( + settings.app_name, + settings.app_version, + get_machine_name(), + get_unique_id() + ) + client.config.data['auth.ssl'] = settings.jellyfin_server_url.startswith( + 'https://') + + +def get_machine_name() -> str: + """ + Retrieves the machine name of the current host. + + Returns: + str: The machine name. + """ + return os.uname().nodename + + +def get_unique_id() -> str: + """ + Retrieves the MAC address of the localhost as a unique identifier. + + Returns: + str: The MAC address. + """ + return get_mac_address(hostname="localhost")