configure client in utils method
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
# 0.1.2
|
# 0.1.2
|
||||||
|
|
||||||
- Extracted utility functions from JellyfinApiClient to JellyfinUtils
|
- Extracted utility functions from JellyfinApiClient to JellyfinUtils
|
||||||
|
- Keep client configuration in Settings class
|
||||||
|
|||||||
@@ -10,23 +10,24 @@ import time
|
|||||||
class JellyfinApiClient:
|
class JellyfinApiClient:
|
||||||
"""
|
"""
|
||||||
Client for interacting with the Jellyfin server API.
|
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):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initializes the Jellyfin API client and authenticates with the server.
|
Initializes the Jellyfin API client and authenticates with the server.
|
||||||
"""
|
"""
|
||||||
self.logger = logging.getLogger('JellyfinApiClient')
|
|
||||||
|
|
||||||
self.logger.info("Connecting to Jellyfin server...")
|
self.logger.info("Connecting to Jellyfin server...")
|
||||||
|
|
||||||
self.client = JellyfinClient()
|
self.client = JellyfinClient()
|
||||||
self.client.config.app('jellydisc', '0.1.2', JellyfinUtils.get_machine_name(), JellyfinUtils.get_unique_id())
|
JellyfinUtils.configure_client(self.client)
|
||||||
self.client.config.data['auth.ssl'] = settings.jellyfin_server_url.startswith(
|
|
||||||
'https://')
|
|
||||||
|
|
||||||
self.last_auth_time = None
|
|
||||||
self.authenticate()
|
self.authenticate()
|
||||||
|
|
||||||
self.logger.info("Connected to Jellyfin server.")
|
self.logger.info("Connected to Jellyfin server.")
|
||||||
|
|
||||||
def authenticate(self):
|
def authenticate(self):
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
|
from jellyfin_apiclient_python import JellyfinClient
|
||||||
from getmac import get_mac_address
|
from getmac import get_mac_address
|
||||||
|
from settings import settings
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class JellyfinUtils:
|
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
|
@staticmethod
|
||||||
def get_machine_name() -> str:
|
def get_machine_name() -> str:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ class Settings(BaseSettings):
|
|||||||
"""
|
"""
|
||||||
Application settings loaded from environment variables or a .env file.
|
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_server_url: str = Field(..., env="JELLYFIN_SERVER_URL")
|
||||||
jellyfin_username: str = Field(..., env="JELLYFIN_USERNAME")
|
jellyfin_username: str = Field(..., env="JELLYFIN_USERNAME")
|
||||||
jellyfin_password: str = Field(..., env="JELLYFIN_PASSWORD")
|
jellyfin_password: str = Field(..., env="JELLYFIN_PASSWORD")
|
||||||
|
|||||||
Reference in New Issue
Block a user