add jellyfin utils folder

This commit is contained in:
2025-12-10 16:15:12 +01:00
parent 946b1605e0
commit b7ff56ced2
3 changed files with 55 additions and 44 deletions

View File

@@ -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,

View File

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

41
jellyfin/utils/config.py Normal file
View File

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