优化wy翻译、罗马音歌词解析
parent
067ca91c4d
commit
5544a469c4
|
@ -70,7 +70,7 @@ export default {
|
||||||
list.push(this.filterData(item))
|
list.push(this.filterData(item))
|
||||||
for (const childItem of item.group) {
|
for (const childItem of item.group) {
|
||||||
const key = item.audio_id + item.hash
|
const key = item.audio_id + item.hash
|
||||||
if (ids.has(key)) return
|
if (ids.has(key)) continue
|
||||||
ids.add(key)
|
ids.add(key)
|
||||||
list.push(this.filterData(childItem))
|
list.push(this.filterData(childItem))
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,8 +105,8 @@ const parseTools = {
|
||||||
lxlrcLines.push(`${startTimeStr}${newWords}`)
|
lxlrcLines.push(`${startTimeStr}${newWords}`)
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
lyricLines: lrcLines,
|
lyric: lrcLines.join('\n'),
|
||||||
lxlyricLines: lxlrcLines,
|
lxlyric: lxlrcLines.join('\n'),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseHeaderInfo(str) {
|
parseHeaderInfo(str) {
|
||||||
|
@ -125,13 +125,40 @@ const parseTools = {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
fixTimeTag(lrcLines, targetLrcLines) {
|
getIntv(interval) {
|
||||||
const timeTagRxp = /^\[[\d:.]+\]/
|
let [m, s, ms] = interval.split(/:|\./)
|
||||||
return targetLrcLines.map((line, index) => {
|
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
|
||||||
const timeTag = timeTagRxp.exec(lrcLines[index])
|
},
|
||||||
if (!timeTag) return line
|
fixTimeTag(lrc, targetlrc) {
|
||||||
return line.replace(timeTagRxp, timeTag[0])
|
let lrcLines = lrc.split('\n')
|
||||||
|
const targetlrcLines = targetlrc.split('\n')
|
||||||
|
const timeRxp = /^\[([\d:.]+)\]/
|
||||||
|
let temp = []
|
||||||
|
let newLrc = []
|
||||||
|
targetlrcLines.forEach((line) => {
|
||||||
|
const result = timeRxp.exec(line)
|
||||||
|
if (!result) return
|
||||||
|
const words = line.replace(timeRxp, '')
|
||||||
|
if (!words.trim()) return
|
||||||
|
const t1 = this.getIntv(result[1])
|
||||||
|
|
||||||
|
while (lrcLines.length) {
|
||||||
|
const lrcLine = lrcLines.shift()
|
||||||
|
const lrcLineResult = timeRxp.exec(lrcLine)
|
||||||
|
if (!lrcLineResult) continue
|
||||||
|
const t2 = this.getIntv(lrcLineResult[1])
|
||||||
|
if (Math.abs(t1 - t2) < 100) {
|
||||||
|
const lrc = line.replace(timeRxp, lrcLineResult[0]).trim()
|
||||||
|
if (!lrc) continue
|
||||||
|
newLrc.push(lrc)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
temp.push(lrcLine)
|
||||||
|
}
|
||||||
|
lrcLines = [...temp, ...lrcLines]
|
||||||
|
temp = []
|
||||||
})
|
})
|
||||||
|
return newLrc.join('\n')
|
||||||
},
|
},
|
||||||
parse(ylrc, ytlrc, yrlrc, lrc, tlrc, rlrc) {
|
parse(ylrc, ytlrc, yrlrc, lrc, tlrc, rlrc) {
|
||||||
const info = {
|
const info = {
|
||||||
|
@ -147,24 +174,24 @@ const parseTools = {
|
||||||
if (ytlrc) {
|
if (ytlrc) {
|
||||||
const lines = this.parseHeaderInfo(ytlrc)
|
const lines = this.parseHeaderInfo(ytlrc)
|
||||||
if (lines) {
|
if (lines) {
|
||||||
if (lines.length == result.lyricLines.length) {
|
// if (lines.length == result.lyricLines.length) {
|
||||||
info.tlyric = this.fixTimeTag(result.lyricLines, lines).join('\n')
|
info.tlyric = this.fixTimeTag(result.lyric, lines.join('\n'))
|
||||||
} else info.tlyric = lines.join('\n')
|
// } else info.tlyric = lines.join('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (yrlrc) {
|
if (yrlrc) {
|
||||||
const lines = this.parseHeaderInfo(yrlrc)
|
const lines = this.parseHeaderInfo(yrlrc)
|
||||||
if (lines) {
|
if (lines) {
|
||||||
if (lines.length == result.lyricLines.length) {
|
// if (lines.length == result.lyricLines.length) {
|
||||||
info.rlyric = this.fixTimeTag(result.lyricLines, lines).join('\n')
|
info.rlyric = this.fixTimeTag(result.lyric, lines.join('\n'))
|
||||||
} else info.rlyric = lines.join('\n')
|
// } else info.rlyric = lines.join('\n')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeRxp = /^\[[\d:.]+\]/
|
const timeRxp = /^\[[\d:.]+\]/
|
||||||
const headers = lines.filter(l => timeRxp.test(l)).join('\n')
|
const headers = lines.filter(l => timeRxp.test(l)).join('\n')
|
||||||
info.lyric = `${headers}\n${result.lyricLines.join('\n')}`
|
info.lyric = `${headers}\n${result.lyric}`
|
||||||
info.lxlyric = result.lxlyricLines.join('\n')
|
info.lxlyric = result.lxlyric
|
||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue