From a5659d90e8729120b1a149dccbcfba5ecb7ff41b Mon Sep 17 00:00:00 2001 From: Zvonimir Rudinski Date: Wed, 10 Dec 2025 11:46:04 +0100 Subject: [PATCH] extract jellyfin utils --- changelog/0.1.2.md | 3 +++ jellyfin/api_client.py | 9 ++------- jellyfin/utils.py | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 changelog/0.1.2.md create mode 100644 jellyfin/utils.py diff --git a/changelog/0.1.2.md b/changelog/0.1.2.md new file mode 100644 index 0000000..38c7b4c --- /dev/null +++ b/changelog/0.1.2.md @@ -0,0 +1,3 @@ +# 0.1.2 + +- Extracted utility functions from JellyfinApiClient to JellyfinUtils diff --git a/jellyfin/api_client.py b/jellyfin/api_client.py index 9ae4d6f..cbb2ecb 100644 --- a/jellyfin/api_client.py +++ b/jellyfin/api_client.py @@ -1,13 +1,11 @@ from settings import settings from jellyfin_apiclient_python import JellyfinClient -from getmac import get_mac_address from jellyfin.models import JellyfinMediaItem, JellyfinMediaType, JellyfinMusicMediaMetadata, JellyfinMovieMediaMetadata, JellyfinEpisodeMediaMetadata +from jellyfin.utils import JellyfinUtils from datetime import datetime from typing import Optional, Tuple import logging import time -import os - class JellyfinApiClient: """ @@ -18,14 +16,11 @@ class JellyfinApiClient: """ Initializes the Jellyfin API client and authenticates with the server. """ - machine_name = os.uname().nodename - unique_id = get_mac_address(hostname="localhost") - self.logger = logging.getLogger('JellyfinApiClient') self.logger.info("Connecting to Jellyfin server...") self.client = JellyfinClient() - self.client.config.app('jellydisc', '0.1.1', machine_name, unique_id) + 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://') diff --git a/jellyfin/utils.py b/jellyfin/utils.py new file mode 100644 index 0000000..708eece --- /dev/null +++ b/jellyfin/utils.py @@ -0,0 +1,23 @@ +from getmac import get_mac_address +import os + +class JellyfinUtils: + @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")