diff --git a/changelog/0.1.2.md b/changelog/0.1.2.md index 38c7b4c..c8bcb3a 100644 --- a/changelog/0.1.2.md +++ b/changelog/0.1.2.md @@ -1,3 +1,4 @@ # 0.1.2 - Extracted utility functions from JellyfinApiClient to JellyfinUtils +- Keep client configuration in Settings class diff --git a/jellyfin/api_client.py b/jellyfin/api_client.py index cbb2ecb..fab880b 100644 --- a/jellyfin/api_client.py +++ b/jellyfin/api_client.py @@ -10,23 +10,24 @@ import time class JellyfinApiClient: """ Client for interacting with the Jellyfin server API. + + Attributes: + last_auth_time (Optional[float]): Timestamp of the last authentication. + logger (logging.Logger): Logger instance for logging messages. """ + last_auth_time: Optional[float] = None + logger: logging.Logger = logging.getLogger('JellyfinApiClient') def __init__(self): """ Initializes the Jellyfin API client and authenticates with the server. """ - self.logger = logging.getLogger('JellyfinApiClient') - self.logger.info("Connecting to Jellyfin server...") + self.client = JellyfinClient() - self.client.config.app('jellydisc', '0.1.2', JellyfinUtils.get_machine_name(), JellyfinUtils.get_unique_id()) - self.client.config.data['auth.ssl'] = settings.jellyfin_server_url.startswith( - 'https://') + JellyfinUtils.configure_client(self.client) - self.last_auth_time = None self.authenticate() - self.logger.info("Connected to Jellyfin server.") def authenticate(self): diff --git a/jellyfin/utils.py b/jellyfin/utils.py index 708eece..ca334a8 100644 --- a/jellyfin/utils.py +++ b/jellyfin/utils.py @@ -1,7 +1,19 @@ +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: """ diff --git a/settings/__init__.py b/settings/__init__.py index 34827bd..565ebfd 100644 --- a/settings/__init__.py +++ b/settings/__init__.py @@ -6,6 +6,9 @@ class Settings(BaseSettings): """ Application settings loaded from environment variables or a .env file. """ + app_name: str = Field('jellydisc') + app_version: str = Field('0.1.2') + jellyfin_server_url: str = Field(..., env="JELLYFIN_SERVER_URL") jellyfin_username: str = Field(..., env="JELLYFIN_USERNAME") jellyfin_password: str = Field(..., env="JELLYFIN_PASSWORD")