Add HTTPS support for server URL
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="url" class="form-label">服务器地址</label>
|
||||
<input type="text" class="form-control" id="url" name="url" placeholder="127.0.0.1">
|
||||
<input type="text" class="form-control" id="url" name="url" placeholder="127.0.0.1 或 https://example.com">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="port" class="form-label">端口</label>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user