Fix: Map the server-returned level to a standardized value

This commit is contained in:
006lp 2024-12-17 20:44:07 +08:00 committed by GitHub
parent ed47e928dd
commit f7069fc6f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -94,10 +94,18 @@ async def url(songId, quality):
if (body["code"] != 200) or (not body.get(data, "")):
raise FailedException("失败")
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 {
'url': data["url"].split("?")[0],
'quality': tools['qualityMapReverse'][data['level']]
'quality': quality
}