-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplex_utils.py
More file actions
32 lines (27 loc) · 834 Bytes
/
plex_utils.py
File metadata and controls
32 lines (27 loc) · 834 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Plex utility functions.
"""
import os
import logging
from typing import Optional
from plexapi.server import PlexServer
from plexapi.myplex import MyPlexAccount
logger = logging.getLogger(__name__)
def get_plex_client() -> Optional[PlexServer]:
"""
Gets the Plex client.
Returns:
The Plex client if available, otherwise None.
"""
plex_url = os.getenv("PLEX_URL")
plex_token = os.getenv("PLEX_TOKEN")
if not plex_url or not plex_token:
logger.error("Plex server is not configured. Please contact the admin.")
return None
try:
account = MyPlexAccount(token=plex_token)
plex = PlexServer(plex_url, account.authenticationToken)
return plex
except Exception as e:
logger.error(f"Failed to connect to Plex server: {e}")
return None