extract jellyfin utils

This commit is contained in:
2025-12-10 11:46:04 +01:00
parent 906b07e20c
commit a5659d90e8
3 changed files with 28 additions and 7 deletions

3
changelog/0.1.2.md Normal file
View File

@@ -0,0 +1,3 @@
# 0.1.2
- Extracted utility functions from JellyfinApiClient to JellyfinUtils

View File

@@ -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://')

23
jellyfin/utils.py Normal file
View File

@@ -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")