From d0363da5e7295141cf3651c492d0160d7593863f Mon Sep 17 00:00:00 2001 From: yizhi <946185759@qq.com> Date: Fri, 10 Mar 2023 17:51:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=B7=E6=88=91=E9=9F=B3?= =?UTF-8?q?=E4=B9=90lrc=E6=AD=8C=E8=AF=8D=E4=B8=8B=E8=BD=BD=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/net/download.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a908375..db50f34 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smart-lyric", - "version": "1.0.3", + "version": "1.0.4", "description": "", "main": "dist/index.js", "types": "typing/index.d.ts", diff --git a/src/net/download.ts b/src/net/download.ts index 76be332..2d7dde8 100644 --- a/src/net/download.ts +++ b/src/net/download.ts @@ -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 (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 } }