Refactor Plex interaction into separate module
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user