修复kuwo歌词解析
parent
aa56dafd5f
commit
ff41fa9829
|
@ -222,8 +222,8 @@ const actions = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async getLrc({ commit, state }, musicInfo) {
|
async getLrc({ commit, state }, musicInfo) {
|
||||||
const lrcInfo = await getStoreLyric(musicInfo)
|
let lrcInfo = await getStoreLyric(musicInfo)
|
||||||
// let lrcInfo = {}
|
// lrcInfo = {}
|
||||||
// if (lrcRequest && lrcRequest.cancelHttp) lrcRequest.cancelHttp()
|
// if (lrcRequest && lrcRequest.cancelHttp) lrcRequest.cancelHttp()
|
||||||
if (existTimeExp.test(lrcInfo.lyric) && lrcInfo.tlyric != null) {
|
if (existTimeExp.test(lrcInfo.lyric) && lrcInfo.tlyric != null) {
|
||||||
// if (musicInfo.lrc.startsWith('\ufeff[id:$00000000]')) {
|
// if (musicInfo.lrc.startsWith('\ufeff[id:$00000000]')) {
|
||||||
|
|
|
@ -192,8 +192,10 @@ export default {
|
||||||
let result = timeExp.exec(line)
|
let result = timeExp.exec(line)
|
||||||
if (result) {
|
if (result) {
|
||||||
const text = line.replace(timeExp, '').trim()
|
const text = line.replace(timeExp, '').trim()
|
||||||
|
let time = RegExp.$1
|
||||||
|
if (/\.\d\d$/.test(time)) time += '0'
|
||||||
lrcArr.push({
|
lrcArr.push({
|
||||||
time: RegExp.$1,
|
time,
|
||||||
text,
|
text,
|
||||||
})
|
})
|
||||||
} else if (lrcTools.rxps.tagLine.test(line)) {
|
} else if (lrcTools.rxps.tagLine.test(line)) {
|
||||||
|
|
|
@ -89,14 +89,26 @@ export const lrcTools = {
|
||||||
isOK: false,
|
isOK: false,
|
||||||
lines: [],
|
lines: [],
|
||||||
tags: [],
|
tags: [],
|
||||||
getWordInfo(str, str2) {
|
getWordInfo(str, str2, prevWord) {
|
||||||
const offset = parseInt(str)
|
const offset = parseInt(str)
|
||||||
const offset2 = parseInt(str2)
|
const offset2 = parseInt(str2)
|
||||||
const startTime = Math.floor((offset + offset2) / (this.offset * 2))
|
let startTime = Math.abs((offset + offset2) / (this.offset * 2))
|
||||||
const timeLength = Math.floor((offset - offset2) / (this.offset2 * 2))
|
let endTime = Math.abs((offset - offset2) / (this.offset2 * 2)) + startTime
|
||||||
|
if (prevWord) {
|
||||||
|
if (startTime < prevWord.endTime) {
|
||||||
|
prevWord.endTime = startTime
|
||||||
|
if (prevWord.startTime > prevWord.endTime) {
|
||||||
|
prevWord.startTime = prevWord.endTime
|
||||||
|
}
|
||||||
|
|
||||||
|
prevWord.newTimeStr = `<${prevWord.startTime},${prevWord.endTime - prevWord.startTime}>`
|
||||||
|
// console.log(prevWord)
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
startTime,
|
startTime,
|
||||||
timeLength,
|
endTime,
|
||||||
|
timeStr: `<${startTime},${endTime - startTime}>`,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseLine(line) {
|
parseLine(line) {
|
||||||
|
@ -111,10 +123,13 @@ export const lrcTools = {
|
||||||
const wordTimes = words.match(this.rxps.wordTimeAll)
|
const wordTimes = words.match(this.rxps.wordTimeAll)
|
||||||
if (!wordTimes) return
|
if (!wordTimes) return
|
||||||
// console.log(wordTimes)
|
// console.log(wordTimes)
|
||||||
|
let preTimeInfo
|
||||||
for (const timeStr of wordTimes) {
|
for (const timeStr of wordTimes) {
|
||||||
const result = this.rxps.wordTime.exec(timeStr)
|
const result = this.rxps.wordTime.exec(timeStr)
|
||||||
const wordInfo = this.getWordInfo(result[1], result[2])
|
const wordInfo = this.getWordInfo(result[1], result[2], preTimeInfo)
|
||||||
words = words.replace(timeStr, `<${wordInfo.startTime},${wordInfo.timeLength}>`)
|
words = words.replace(timeStr, wordInfo.timeStr)
|
||||||
|
if (preTimeInfo?.newTimeStr) words = words.replace(preTimeInfo.timeStr, preTimeInfo.newTimeStr)
|
||||||
|
preTimeInfo = wordInfo
|
||||||
}
|
}
|
||||||
this.lines.push(time + words)
|
this.lines.push(time + words)
|
||||||
return
|
return
|
||||||
|
@ -127,8 +142,8 @@ export const lrcTools = {
|
||||||
content = content.substring(0, content.indexOf(']['))
|
content = content.substring(0, content.indexOf(']['))
|
||||||
}
|
}
|
||||||
const valueOf = parseInt(content, 8)
|
const valueOf = parseInt(content, 8)
|
||||||
this.offset = Math.floor(valueOf / 10)
|
this.offset = Math.trunc(valueOf / 10)
|
||||||
this.offset2 = Math.floor(valueOf % 10)
|
this.offset2 = Math.trunc(valueOf % 10)
|
||||||
if (this.offset == 0 || Number.isNaN(this.offset) || this.offset2 == 0 || Number.isNaN(this.offset2)) {
|
if (this.offset == 0 || Number.isNaN(this.offset) || this.offset2 == 0 || Number.isNaN(this.offset2)) {
|
||||||
this.isOK = false
|
this.isOK = false
|
||||||
}
|
}
|
||||||
|
@ -147,12 +162,13 @@ export const lrcTools = {
|
||||||
tools.tags = []
|
tools.tags = []
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
if (!tools.isOK) return ''
|
if (!tools.isOK) throw new Error('failed')
|
||||||
tools.parseLine(line)
|
tools.parseLine(line)
|
||||||
}
|
}
|
||||||
if (!tools.lines.length) return ''
|
if (!tools.lines.length) return ''
|
||||||
let lrcs = tools.lines.join('\n')
|
let lrcs = tools.lines.join('\n')
|
||||||
if (tools.tags.length) lrcs = `${tools.tags.join('\n')}\n${lrcs}`
|
if (tools.tags.length) lrcs = `${tools.tags.join('\n')}\n${lrcs}`
|
||||||
|
// console.log(lrcs)
|
||||||
return lrcs
|
return lrcs
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue