Skip to content

Commit

Permalink
添加对wy源某些歌曲有问题的歌词进行修复(lyswhut#370
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Dec 12, 2023
1 parent 5a41812 commit 0cf70b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions publish/changeLog.md
Expand Up @@ -11,6 +11,7 @@
- 更新播放栏进度条样式,进度条允许拖动调整进度
- 优化播放详情页歌曲封面、控制按钮对各尺寸屏幕的适配,修改横屏下的控制栏按钮布局
- 优化横竖屏界面的暂时判断,现在趋于方屏的屏幕按竖屏的方式显示,横屏下的播放栏添加上一曲切歌按钮
- 添加对wy源某些歌曲有问题的歌词进行修复(#370

### 修复

Expand Down
26 changes: 22 additions & 4 deletions src/utils/musicSdk/wy/lyric.js
Expand Up @@ -126,7 +126,10 @@ const parseTools = {
})
},
getIntv(interval) {
let [m, s, ms] = interval.split(/:|\./)
if (!interval.includes('.')) interval += '.0'
let arr = interval.split(/:|\./)
while (arr.length < 3) arr.unshift('0')
const [m, s, ms] = arr
return parseInt(m) * 3600000 + parseInt(s) * 1000 + parseInt(ms)
},
fixTimeTag(lrc, targetlrc) {
Expand Down Expand Up @@ -243,6 +246,20 @@ const parseTools = {
// return requestObj
// }

// https://github.com/lyswhut/lx-music-mobile/issues/370
const fixTimeLabel = (lrc, tlrc, romalrc) => {
if (lrc) {
let newLrc = lrc.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]')
let newTlrc = tlrc?.replace(/\[(\d{2}:\d{2}):(\d{2})]/g, '[$1.$2]') ?? tlrc
if (newLrc != lrc || newTlrc != tlrc) {
lrc = newLrc
tlrc = newTlrc
if (romalrc) romalrc = romalrc.replace(/\[(\d{2}:\d{2}):(\d{2,3})]/g, '[$1.$2]').replace(/\[(\d{2}:\d{2}\.\d{2})0]/g, '[$1]')
}
}

return { lrc, tlrc, romalrc }
}

// https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/module/lyric_new.js
export default songmid => {
Expand All @@ -258,10 +275,11 @@ export default songmid => {
yrv: 0,
})
requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body)
console.log(body)
if (body.code !== 200 || !body?.lrc?.lyric) return Promise.reject(new Error('Get lyric failed'))
const info = parseTools.parse(body.yrc?.lyric, body.ytlrc?.lyric, body.yromalrc?.lyric, body.lrc.lyric, body.tlyric?.lyric, body.romalrc?.lyric)
// console.log(info)
const fixTimeLabelLrc = fixTimeLabel(body.lrc.lyric, body.tlyric?.lyric, body.romalrc?.lyric)
const info = parseTools.parse(body.yrc?.lyric, body.ytlrc?.lyric, body.yromalrc?.lyric, fixTimeLabelLrc.lrc, fixTimeLabelLrc.tlrc, fixTimeLabelLrc.romalrc)
console.log(info)
if (!info.lyric) return Promise.reject(new Error('Get lyric failed'))
return info
})
Expand Down

0 comments on commit 0cf70b3

Please sign in to comment.