Compare commits
3 Commits
906b07e20c
...
946b1605e0
| Author | SHA1 | Date | |
|---|---|---|---|
|
946b1605e0
|
|||
|
32e4a76cd1
|
|||
|
a5659d90e8
|
4
changelog/0.1.2.md
Normal file
4
changelog/0.1.2.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# 0.1.2
|
||||||
|
|
||||||
|
- Extracted utility functions from JellyfinApiClient to JellyfinUtils
|
||||||
|
- Keep client configuration in Settings class
|
||||||
@@ -7,17 +7,21 @@ import logging
|
|||||||
class DiscordRPC:
|
class DiscordRPC:
|
||||||
"""
|
"""
|
||||||
Client for interacting with Discord Rich Presence (RPC).
|
Client for interacting with Discord Rich Presence (RPC).
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
logger (logging.Logger): Logger instance for logging messages.
|
||||||
"""
|
"""
|
||||||
|
logger: logging.Logger = logging.getLogger('DiscordRPC')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initializes the Discord RPC client and connects to Discord via IPC.
|
Initializes the Discord RPC client and connects to Discord via IPC.
|
||||||
"""
|
"""
|
||||||
self.logger = logging.getLogger('DiscordRPC')
|
|
||||||
|
|
||||||
self.logger.info("Connecting to Discord RPC...")
|
self.logger.info("Connecting to Discord RPC...")
|
||||||
|
|
||||||
self.rpc = Presence(settings.discord_app_id)
|
self.rpc = Presence(settings.discord_app_id)
|
||||||
self.rpc.connect()
|
self.rpc.connect()
|
||||||
|
|
||||||
self.logger.info("Connected to Discord RPC.")
|
self.logger.info("Connected to Discord RPC.")
|
||||||
|
|
||||||
def update(self, payload: DiscordRPCUpdatePayload):
|
def update(self, payload: DiscordRPCUpdatePayload):
|
||||||
@@ -38,6 +42,7 @@ class DiscordRPC:
|
|||||||
start=payload.start,
|
start=payload.start,
|
||||||
end=payload.end
|
end=payload.end
|
||||||
)
|
)
|
||||||
|
|
||||||
self.logger.info("Discord RPC presence updated.")
|
self.logger.info("Discord RPC presence updated.")
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
@@ -45,5 +50,7 @@ class DiscordRPC:
|
|||||||
Clears the Discord RPC presence.
|
Clears the Discord RPC presence.
|
||||||
"""
|
"""
|
||||||
self.logger.info("Clearing Discord RPC presence...")
|
self.logger.info("Clearing Discord RPC presence...")
|
||||||
|
|
||||||
self.rpc.clear()
|
self.rpc.clear()
|
||||||
|
|
||||||
self.logger.info("Discord RPC presence cleared.")
|
self.logger.info("Discord RPC presence cleared.")
|
||||||
|
|||||||
@@ -1,37 +1,34 @@
|
|||||||
from settings import settings
|
from settings import settings
|
||||||
from jellyfin_apiclient_python import JellyfinClient
|
from jellyfin_apiclient_python import JellyfinClient
|
||||||
from getmac import get_mac_address
|
|
||||||
from jellyfin.models import JellyfinMediaItem, JellyfinMediaType, JellyfinMusicMediaMetadata, JellyfinMovieMediaMetadata, JellyfinEpisodeMediaMetadata
|
from jellyfin.models import JellyfinMediaItem, JellyfinMediaType, JellyfinMusicMediaMetadata, JellyfinMovieMediaMetadata, JellyfinEpisodeMediaMetadata
|
||||||
|
from jellyfin.utils import JellyfinUtils
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
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.logger.info("Connecting to Jellyfin server...")
|
||||||
|
|
||||||
self.client = JellyfinClient()
|
self.client = JellyfinClient()
|
||||||
self.client.config.app('jellydisc', '0.1.1', machine_name, 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):
|
||||||
|
|||||||
37
jellyfin/utils.py
Normal file
37
jellyfin/utils.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
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")
|
||||||
@@ -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