Add HTTPS support for server URL

This commit is contained in:
Koha9
2025-06-21 19:20:48 +09:00
parent 8fa0189a1d
commit 7ab55e3ae4
3 changed files with 12 additions and 2 deletions
+10 -1
View File
@@ -1,5 +1,6 @@
from plexapi.myplex import MyPlexAccount
from plexapi.server import PlexServer
from urllib.parse import urlparse
def connect_plex(config, username, password, url, port="32400"):
@@ -10,7 +11,15 @@ def connect_plex(config, username, password, url, port="32400"):
token = account.authenticationToken
config["token"] = token
base_url = f"http://{url}:{port}"
parsed = urlparse(url)
if parsed.scheme in ("http", "https"):
netloc = parsed.netloc or parsed.path
if ":" not in netloc and port:
netloc = f"{netloc}:{port}"
base_url = f"{parsed.scheme}://{netloc}"
else:
base_url = f"http://{url}:{port}"
server = PlexServer(base_url, token)
config.update({"server_url": url, "server_port": port})
return server