修复酷我音乐lrc歌词下载解析问题

This commit is contained in:
2023-03-10 17:51:16 +08:00
parent e899fd6563
commit d0363da5e7
2 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "smart-lyric", "name": "smart-lyric",
"version": "1.0.3", "version": "1.0.4",
"description": "", "description": "",
"main": "dist/index.js", "main": "dist/index.js",
"types": "typing/index.d.ts", "types": "typing/index.d.ts",

View File

@ -238,9 +238,18 @@ export async function downloadKuwoLyric(option: IKuwoLyricDownloadOption): Promi
} }
} }
const isLyric = (str: string) => /^\[[0-9a-zA-Z]+:/.test(str)
const tryParseRegular = (buffer: Buffer) => {
let result: string | null = lrcxUtil.decrypt(buffer)
if (!result || !isLyric(result)) result = iconv.decode(zlib.inflateSync(buffer), 'gb18030')
if (result && isLyric(result)) return result
return null
}
if (buffer.byteLength && baseInfo.lrc_length) { if (buffer.byteLength && baseInfo.lrc_length) {
if (baseInfo.lrcx) return { karaok: lrcxUtil.decrypt(buffer), regular: null } if (baseInfo.lrcx) return { karaok: lrcxUtil.decrypt(buffer), regular: null }
else return { karaok: null, regular: iconv.decode(zlib.inflateSync(buffer), 'gb18030') } else return { karaok: null, regular: tryParseRegular(buffer) }
} }
return { karaok: null, regular: null } return { karaok: null, regular: null }
} }