Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,19 +406,34 @@ export const handleSongQuality = (
if (song >= 160000) return QualityType.MQ;
return QualityType.LQ;
}
// 含有 level 特殊处理
if (typeof song === "object" && "level" in song) {
if (song.level === "jymaster") return QualityType.Master;
if (song.level === "dolby") return QualityType.Dolby;
if (song.level === "sky") return QualityType.Spatial;
if (song.level === "jyeffect") return QualityType.Surround;
if (song.level === "hires") return QualityType.HiRes;
if (song.level === "lossless") return QualityType.SQ;
if (song.level === "exhigh") return QualityType.HQ;
if (song.level === "higher") return QualityType.MQ;
if (song.level === "standard") return QualityType.LQ;
return undefined;

const levelQualityMap = {
"jymaster": QualityType.Master,
"dolby": QualityType.Dolby,
"sky": QualityType.Spatial,
"jyeffect": QualityType.Surround,
"hires": QualityType.HiRes,
"lossless": QualityType.SQ,
"exhigh": QualityType.HQ,
"higher": QualityType.MQ,
"standard": QualityType.LQ,
}
Comment on lines +410 to +420
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高性能,可以考虑将 levelQualityMap 移到 handleSongQuality 函数外部。由于它是一个常量,在模块作用域定义可以避免每次函数调用时都重新创建它。如果这个函数被频繁调用,这样做的好处会很明显。


if (typeof song === "object" && song) {
// 含有 level 特殊处理
if ("level" in song) {
const quality = levelQualityMap[song.level];
if (quality) return quality;
}
// 云盘歌曲适配
if ("privilege" in song) {
const privilege = song.privilege;
const quality = levelQualityMap[privilege?.playMaxBrLevel]
?? levelQualityMap[privilege?.plLevel];
if (quality) return quality;
}
}

const order = [
{ key: "jm", type: QualityType.Master },
{ key: "db", type: QualityType.Dolby },
Expand Down