Compare commits
No commits in common. "8fa0189a1dd6f7e6a136a497aca6f28b10a33473" and "78422a7d332a62daaa6b4f09b8e75710bb34076f" have entirely different histories.
8fa0189a1d
...
78422a7d33
@ -12,11 +12,6 @@ PlexPlaylistSync 是一个用于同步 Plex 播放列表和本地 `.m3u`/`.m3u8`
|
|||||||
- **低功耗运行**: 适合 NAS 或服务器 24 小时运行,优化资源使用,减少能耗。
|
- **低功耗运行**: 适合 NAS 或服务器 24 小时运行,优化资源使用,减少能耗。
|
||||||
- **Docker 部署**: 可通过 Docker 轻松部署和运行。
|
- **Docker 部署**: 可通过 Docker 轻松部署和运行。
|
||||||
|
|
||||||
### Token 登录
|
|
||||||
|
|
||||||
首次登录时使用用户名和密码连接 Plex 服务器,成功后程序会将获得的 `token` 保存在配置文件中,后续通信仅使用该 `token`,不再保存明文密码。
|
|
||||||
默认情况下 Plex 服务器使用 `32400` 端口,可在未修改服务器端口时直接使用该默认值。
|
|
||||||
|
|
||||||
## 安装
|
## 安装
|
||||||
|
|
||||||
首先安装依赖:
|
首先安装依赖:
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
{
|
{
|
||||||
"theme": "auto",
|
"theme": "light"
|
||||||
"token": "",
|
|
||||||
"server_url": "",
|
|
||||||
"server_port": "32400"
|
|
||||||
}
|
}
|
33
app/main.py
33
app/main.py
@ -4,7 +4,6 @@ from fastapi import FastAPI, Request, Form
|
|||||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
from app.utils.plex_client import connect_plex
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
templates = Jinja2Templates(directory=os.path.join(os.path.dirname(__file__), "templates"))
|
templates = Jinja2Templates(directory=os.path.join(os.path.dirname(__file__), "templates"))
|
||||||
@ -32,34 +31,16 @@ async def login(
|
|||||||
user: str = Form(...),
|
user: str = Form(...),
|
||||||
pw: str = Form(...),
|
pw: str = Form(...),
|
||||||
url: str = Form(...),
|
url: str = Form(...),
|
||||||
port: str = Form("32400")
|
port: str = Form(...),
|
||||||
|
library: str = Form(...)
|
||||||
):
|
):
|
||||||
config = load_config()
|
config = load_config()
|
||||||
theme = config.get("theme", "auto")
|
theme = config.get("theme", "auto")
|
||||||
try:
|
# demo:假装连接成功
|
||||||
connect_plex(config, user, pw, url, port)
|
if user == "admin":
|
||||||
save_config(config)
|
return templates.TemplateResponse("login.html", {"request": request, "message": "连接成功", "success": True, "theme": theme, "path": "/login"})
|
||||||
return templates.TemplateResponse(
|
else:
|
||||||
"login.html",
|
return templates.TemplateResponse("login.html", {"request": request, "message": "连接失败:用户名错误", "success": False, "theme": theme, "path": "/login"})
|
||||||
{
|
|
||||||
"request": request,
|
|
||||||
"message": "连接成功",
|
|
||||||
"success": True,
|
|
||||||
"theme": theme,
|
|
||||||
"path": "/login",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
return templates.TemplateResponse(
|
|
||||||
"login.html",
|
|
||||||
{
|
|
||||||
"request": request,
|
|
||||||
"message": f"连接失败:{str(e)}",
|
|
||||||
"success": False,
|
|
||||||
"theme": theme,
|
|
||||||
"path": "/login",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
@app.get("/playlist", response_class=HTMLResponse)
|
@app.get("/playlist", response_class=HTMLResponse)
|
||||||
async def get_playlist(request: Request):
|
async def get_playlist(request: Request):
|
||||||
|
@ -19,7 +19,14 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="port" class="form-label">端口</label>
|
<label for="port" class="form-label">端口</label>
|
||||||
<input type="text" class="form-control" id="port" name="port" value="32400">
|
<input type="text" class="form-control" id="port" name="port" placeholder="32400">
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="library" class="form-label">选择库</label>
|
||||||
|
<select class="form-select" id="library" name="library">
|
||||||
|
<option>Music</option>
|
||||||
|
<option>Podcast</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary">连接</button>
|
<button type="submit" class="btn btn-primary">连接</button>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
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
|
|
@ -2,4 +2,3 @@ fastapi
|
|||||||
uvicorn[standard]
|
uvicorn[standard]
|
||||||
jinja2
|
jinja2
|
||||||
python-multipart
|
python-multipart
|
||||||
plexapi
|
|
||||||
|
Loading…
Reference in New Issue
Block a user