跳过空白歌词

pull/930/merge
lyswhut 2022-04-10 22:25:25 +08:00
parent 1c542a9b17
commit e75863e99d
3 changed files with 8 additions and 7 deletions

View File

@ -153,6 +153,7 @@ const getPic = function(musicInfo, retryedSource = [], originMusic) {
}) })
} }
const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
const handleGetLyric = function(musicInfo, retryedSource = [], originMusic) { const handleGetLyric = function(musicInfo, retryedSource = [], originMusic) {
if (!originMusic) originMusic = musicInfo if (!originMusic) originMusic = musicInfo
let reqPromise let reqPromise
@ -162,8 +163,7 @@ const handleGetLyric = function(musicInfo, retryedSource = [], originMusic) {
reqPromise = Promise.reject(err) reqPromise = Promise.reject(err)
} }
return reqPromise.then(lyricInfo => { return reqPromise.then(lyricInfo => {
if (!lyricInfo.lyric.trim()) return Promise.reject(new Error('failed')) return existTimeExp.test(lyricInfo.lyric) ? lyricInfo : Promise.reject(new Error('failed'))
return lyricInfo
}).catch(err => { }).catch(err => {
// console.log(err) // console.log(err)
if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source) if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source)
@ -184,7 +184,7 @@ const handleGetLyric = function(musicInfo, retryedSource = [], originMusic) {
const getLyric = function(musicInfo, isUseOtherSource, isS2t) { const getLyric = function(musicInfo, isUseOtherSource, isS2t) {
return getLyricFromStorage(musicInfo).then(lrcInfo => { return getLyricFromStorage(musicInfo).then(lrcInfo => {
return ( return (
lrcInfo.lyric && lrcInfo.lyric.trim() existTimeExp.test(lrcInfo.lyric)
? Promise.resolve({ lyric: lrcInfo.lyric, tlyric: lrcInfo.tlyric || '' }) ? Promise.resolve({ lyric: lrcInfo.lyric, tlyric: lrcInfo.tlyric || '' })
: ( : (
isUseOtherSource isUseOtherSource

View File

@ -150,6 +150,7 @@ const getPic = function(musicInfo, retryedSource = [], originMusic) {
}) })
}) })
} }
const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
const getLyric = function(musicInfo, retryedSource = [], originMusic) { const getLyric = function(musicInfo, retryedSource = [], originMusic) {
if (!originMusic) originMusic = musicInfo if (!originMusic) originMusic = musicInfo
let reqPromise let reqPromise
@ -159,8 +160,7 @@ const getLyric = function(musicInfo, retryedSource = [], originMusic) {
reqPromise = Promise.reject(err) reqPromise = Promise.reject(err)
} }
return reqPromise.then(lyricInfo => { return reqPromise.then(lyricInfo => {
if (!lyricInfo.lyric.trim()) return Promise.reject(new Error('failed')) return existTimeExp.test(lyricInfo.lyric) ? lyricInfo : Promise.reject(new Error('failed'))
return lyricInfo
}).catch(err => { }).catch(err => {
if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source) if (!retryedSource.includes(musicInfo.source)) retryedSource.push(musicInfo.source)
return this.dispatch('list/getOtherSource', originMusic).then(otherSource => { return this.dispatch('list/getOtherSource', originMusic).then(otherSource => {
@ -216,7 +216,7 @@ const actions = {
const lrcInfo = await getStoreLyric(musicInfo) const lrcInfo = await getStoreLyric(musicInfo)
// lrcInfo = {} // lrcInfo = {}
// if (lrcRequest && lrcRequest.cancelHttp) lrcRequest.cancelHttp() // if (lrcRequest && lrcRequest.cancelHttp) lrcRequest.cancelHttp()
if (lrcInfo.lyric && lrcInfo.lyric.trim() && 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]')) {
// let str = musicInfo.lrc.replace('\ufeff[id:$00000000]\n', '') // let str = musicInfo.lrc.replace('\ufeff[id:$00000000]\n', '')
// commit('setLrc', { musicInfo, lyric: str, tlyric: musicInfo.tlrc, lxlyric: musicInfo.tlrc }) // commit('setLrc', { musicInfo, lyric: str, tlyric: musicInfo.tlrc, lxlyric: musicInfo.tlrc })

View File

@ -91,6 +91,7 @@ const buildParams = (id, isGetLyricx) => {
// console.log(buildParams('207527604', true)) // console.log(buildParams('207527604', true))
const timeExp = /^\[([\d:.]*)\]{1}/g const timeExp = /^\[([\d:.]*)\]{1}/g
const existTimeExp = /\[\d{1,2}:.*\d{1,4}\]/
export default { export default {
sortLrcArr(arr) { sortLrcArr(arr) {
const lrcSet = new Set() const lrcSet = new Set()
@ -201,7 +202,7 @@ export default {
lrcInfo.lxlyric = '' lrcInfo.lxlyric = ''
} }
lrcInfo.lyric = lrcInfo.lyric.replace(lrcTools.rxps.wordTimeAll, '') lrcInfo.lyric = lrcInfo.lyric.replace(lrcTools.rxps.wordTimeAll, '')
if (!lrcInfo.lyric.trim()) return Promise.reject(new Error('Get lyric failed')) if (!existTimeExp.test(lrcInfo.lyric)) return Promise.reject(new Error('Get lyric failed'))
// console.log(lrcInfo) // console.log(lrcInfo)
return lrcInfo return lrcInfo
}) })