Add HTTPS support for server URL
This commit is contained in:
parent
8fa0189a1d
commit
7ab55e3ae4
@ -16,6 +16,7 @@ PlexPlaylistSync 是一个用于同步 Plex 播放列表和本地 `.m3u`/`.m3u8`
|
||||
|
||||
首次登录时使用用户名和密码连接 Plex 服务器,成功后程序会将获得的 `token` 保存在配置文件中,后续通信仅使用该 `token`,不再保存明文密码。
|
||||
默认情况下 Plex 服务器使用 `32400` 端口,可在未修改服务器端口时直接使用该默认值。
|
||||
服务器地址字段支持包含 `http://` 或 `https://` 前缀,当提供 `https://` 前缀时将使用 HTTPS 连接。
|
||||
|
||||
## 安装
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user