Refactor Plex interaction into separate module

This commit is contained in:
Koha9
2025-06-20 21:54:55 +09:00
parent 78422a7d33
commit aa4223b413
5 changed files with 51 additions and 6 deletions
+16
View File
@@ -0,0 +1,16 @@
from plexapi.myplex import MyPlexAccount
from plexapi.server import PlexServer
def connect_plex(config, username, password, url, port, library):
"""Return a connected PlexServer instance and update config with token and server info."""
token = config.get("token")
if not token:
account = MyPlexAccount(username, password)
token = account.authenticationToken
config["token"] = token
base_url = f"http://{url}:{port}"
server = PlexServer(base_url, token)
config.update({"server_url": url, "server_port": port, "library": library})
return server