fix: attempt to fix quality level comparison logic in wy module (#98)

Main improvements:
1. Added explicit server response level comparison logic
2. Fixed data field reference error in NCMAPI path
3. Unified quality validation process between official and NCMAPI interfaces
This commit is contained in:
006lp 2025-03-22 01:27:21 +08:00 committed by GitHub
parent c175312307
commit e13b7e3831
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -72,9 +72,17 @@ async def url(songId, quality):
raise FailedException("失败") raise FailedException("失败")
data = body["data"][0] data = body["data"][0]
if (data['level'] != tools['qualityMap'][quality]):
raise FailedException("reject unmatched quality") # 修正:映射服务器返回的 level 为标准化值
data_level = data['level']
expected_level = tools["qualityMap"][quality]
# 检查客户端请求的 quality 与服务器返回的 level 是否匹配
if data_level != expected_level:
raise FailedException(
f"reject unmatched quality: expected={expected_level}, got={data_level}"
)
return { return {
'url': data["url"].split("?")[0], 'url': data["url"].split("?")[0],
'quality': tools['qualityMapReverse'][data['level']] 'quality': tools['qualityMapReverse'][data['level']]
@ -91,7 +99,7 @@ async def url(songId, quality):
"params": requestBody "params": requestBody
}) })
body = req.json() body = req.json()
if (body["code"] != 200) or (not body.get(data, "")): if (body["code"] != 200) or (not body.get("data")):
raise FailedException("失败") raise FailedException("失败")
data = body["data"][0] data = body["data"][0]