修复lrcx下载和解析问题
This commit is contained in:
@ -2,6 +2,7 @@ import zlib from 'zlib'
|
||||
import iconv from 'iconv-lite'
|
||||
import { IKaraokeWord, ILyric, ILyricLine, LyricType } from './declare'
|
||||
import { genLyricTag, parseLyricTag } from './common'
|
||||
import { parse as parseLrc } from './lrc'
|
||||
|
||||
|
||||
const KUWO_LYRIC_KEY = Buffer.from('yeelion')
|
||||
@ -22,13 +23,20 @@ function cryptLRCX(buffer: Buffer) {
|
||||
export function decrypt(buffer: Buffer) {
|
||||
try {
|
||||
//解压
|
||||
const b64Str = zlib.inflateSync(buffer).toString()
|
||||
//取得内容
|
||||
const content = Buffer.from(b64Str, 'base64')
|
||||
//解密
|
||||
cryptLRCX(content)
|
||||
const b64Buffer = zlib.inflateSync(buffer)
|
||||
const b64Str = b64Buffer.toString()
|
||||
//不需要解码
|
||||
if (/\s*\[[a-z0-9A-z]+:/.test(b64Str)) return iconv.decode(b64Buffer, 'gb18030')
|
||||
//进行解码
|
||||
else {
|
||||
//取得内容
|
||||
const content = Buffer.from(b64Str, 'base64')
|
||||
//解密
|
||||
cryptLRCX(content)
|
||||
//return
|
||||
return iconv.decode(content, 'gb18030')
|
||||
}
|
||||
//完成
|
||||
return iconv.decode(content, 'gb18030')
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
@ -54,6 +62,9 @@ export function encrypt(content: string | Buffer) {
|
||||
* @param lrcxText LRCX歌词文本内容
|
||||
*/
|
||||
export function parse(lrcxText: string) {
|
||||
//如果不是lrcx则按照lrc解析
|
||||
if (!/^\[kuwo:\d+\]$/im.test(lrcxText)) return parseLrc(lrcxText)
|
||||
|
||||
//结果
|
||||
const result: ILyric = { type: LyricType.KARA, content: [] }
|
||||
|
||||
|
Reference in New Issue
Block a user