增加歌词分类

This commit is contained in:
2023-02-10 15:49:33 +08:00
parent 20ea76cb1a
commit e899fd6563
9 changed files with 82 additions and 61 deletions

View File

@ -17,7 +17,7 @@ function toInt(v: string | number) {
* @param line 歌词行
*/
export function parseLyricTag(lyric: ILyric, line: string) {
const match = line.match(/^\[([a-zA-Z][a-zA-Z0-9_]*):(.*)\]$/)
const match = line.match(/^\[([a-zA-Z#][a-zA-Z0-9_]*):(.*)\]$/)
if (!match) return false
switch (match[1]) {
case 'ti':

View File

@ -2,7 +2,6 @@ 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')
@ -23,19 +22,13 @@ function cryptLRCX(buffer: Buffer) {
export function decrypt(buffer: Buffer) {
try {
//解压
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')
}
const b64Str = zlib.inflateSync(buffer).toString()
//取得内容
const content = Buffer.from(b64Str, 'base64')
//解密
cryptLRCX(content)
//return
return iconv.decode(content, 'gb18030')
//完成
} catch (err) {
return null
@ -62,9 +55,6 @@ 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: [] }