chore: 补充封面本地化测试脚本、收尾清理

This commit is contained in:
dev committed 2026-09-24 20:35:34 +08:00
1 parent 65b6f8cf62
commit f96a4bae51
1 file changed
+44
+44
View File
@@ -0,0 +1,44 @@
import urllib.request, urllib.error, http.cookiejar, json, sys
BASE = "http://127.0.0.1:3000"
cj = http.cookiejar.CookieJar()
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
def call(path, method="GET", data=None):
body = json.dumps(data).encode() if data is not None else None
req = urllib.request.Request(BASE + path, data=body, method=method)
if body: req.add_header("Content-Type", "application/json")
try:
r = op.open(req, timeout=60)
return r.status, r.read()
except urllib.error.HTTPError as e:
return e.code, e.read()
call("/api/auth/login", "POST", {"password": "test123"})
st, body = call("/api/resources")
songs = json.loads(body)["list"]
print(f"共 {len(songs)} 首,开始补全元数据...\n")
ok, fail = 0, 0
for s in songs:
st, body = call("/api/music/enrich", "POST", {"file": s["file"]})
if st == 200:
d = json.loads(body)
song = d.get("song", {})
cover = song.get("cover", "")
artist = song.get("artist", "")
status = "✓ 有封面" if cover else "○ 无封面"
print(f" {status} | {song.get('name','')} - {artist} | {cover}")
ok += 1
else:
print(f" ✗ 失败: {s['file']} -> {body[:80]}")
fail += 1
print(f"\n完成: {ok} 成功, {fail} 失败")
# 最终确认
st, body = call("/api/resources")
songs = json.loads(body)["list"]
with_cover = sum(1 for s in songs if s["albumImage"])
print(f"资源库: {len(songs)} 首,其中 {with_cover} 首有本地封面")
sys.exit(0)