From f96a4bae5187600450054d2c209660ede682a0ea Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 24 Sep 2026 20:35:34 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=A1=A5=E5=85=85=E5=B0=81=E9=9D=A2?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=8C=96=E6=B5=8B=E8=AF=95=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E3=80=81=E6=94=B6=E5=B0=BE=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_enrich.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 test_enrich.py diff --git a/test_enrich.py b/test_enrich.py new file mode 100644 index 0000000..cfda1c8 --- /dev/null +++ b/test_enrich.py @@ -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) \ No newline at end of file