17 lines
577 B
Python
17 lines
577 B
Python
from plexapi.myplex import MyPlexAccount
|
|
from plexapi.server import PlexServer
|
|
|
|
|
|
def connect_plex(config, username, password, url, port="32400"):
|
|
"""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})
|
|
return server
|