新增显示歌词翻译设置,默认开启
This commit is contained in:
@@ -21,7 +21,7 @@ const bd = {
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
const requestObj = this.getMusicInfo(songInfo)
|
||||
requestObj.promise = requestObj.promise.then(info => httpFetch(info.lrclink).promise.then(resp => resp.body))
|
||||
requestObj.promise = requestObj.promise.then(info => httpFetch(info.lrclink).promise.then(resp => ({ lyric: resp.body, tlyric: '' })))
|
||||
return requestObj
|
||||
},
|
||||
// getLyric(songInfo) {
|
||||
|
||||
@@ -26,7 +26,10 @@ export default {
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
return body
|
||||
return {
|
||||
lyric: body,
|
||||
tlyric: '',
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
|
||||
@@ -17,7 +17,10 @@ export default {
|
||||
return requestObj.promise.then(({ statusCode, body, raw }) => {
|
||||
if (statusCode != 200) return Promise.reject(new Error(JSON.stringify(body)))
|
||||
return decodeLyric({ lrcBase64: raw.toString('base64'), isGetLyricx }).then(base64Data => {
|
||||
return Buffer.from(base64Data, 'base64').toString()
|
||||
return {
|
||||
lyric: Buffer.from(base64Data, 'base64').toString(),
|
||||
tlyric: '',
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -12,7 +12,10 @@ export default {
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
return body
|
||||
return {
|
||||
lyric: body,
|
||||
tlyric: '',
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
} else {
|
||||
@@ -28,7 +31,10 @@ export default {
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
return body.lyric
|
||||
return {
|
||||
lyric: body.lyric,
|
||||
tlyric: '',
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
}
|
||||
|
||||
@@ -6,13 +6,17 @@ export default {
|
||||
matchLrc: /.+"lyric":"([\w=+/]*)".+/,
|
||||
},
|
||||
getLyric(songmid) {
|
||||
const requestObj = httpFetch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=2001461048&loginUin=0&hostUin=0&format=jsonp&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
|
||||
const requestObj = httpFetch(`https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?songmid=${songmid}&g_tk=5381&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&platform=yqq`, {
|
||||
headers: {
|
||||
Referer: 'https://y.qq.com/portal/player.html',
|
||||
},
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
return decodeName(b64DecodeUnicode(body.replace(this.regexps.matchLrc, '$1')))
|
||||
if (body.code != 0) return Promise.reject(new Error('获取歌词失败'))
|
||||
return {
|
||||
lyric: decodeName(b64DecodeUnicode(body.lyric)),
|
||||
tlyric: decodeName(b64DecodeUnicode(body.trans)),
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
import { httpFetch } from '../../request'
|
||||
import { weapi } from './utils/crypto'
|
||||
import { linuxapi } from './utils/crypto'
|
||||
|
||||
export default songmid => {
|
||||
const requestObj = httpFetch('http://music.163.com/weapi/song/lyric?csrf_token=', {
|
||||
const requestObj = httpFetch('https://music.163.com/api/linux/forward', {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||
Referer: 'https://music.163.com/song?id=' + songmid,
|
||||
origin: 'https://music.163.com',
|
||||
},
|
||||
form: weapi({ id: songmid, lv: -1, tv: -1, csrf_token: '' }),
|
||||
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36',
|
||||
form: linuxapi({
|
||||
method: 'POST',
|
||||
url: 'https://music.163.com/api/song/lyric',
|
||||
params: {
|
||||
id: songmid,
|
||||
lv: -1,
|
||||
kv: -1,
|
||||
tv: -1,
|
||||
},
|
||||
}),
|
||||
})
|
||||
requestObj.promise = requestObj.promise.then(({ body }) => {
|
||||
// console.log(body)
|
||||
if (body.code !== 200) return Promise.reject('获取歌词失败')
|
||||
return body.lrc.lyric
|
||||
return {
|
||||
lyric: body.lrc.lyric,
|
||||
tlyric: body.tlyric.lyric,
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
}
|
||||
|
||||
@@ -1,6 +1,23 @@
|
||||
import { httpGet, httpFetch } from '../../request'
|
||||
import { xmRequest } from './util'
|
||||
|
||||
const parseLyric = str => {
|
||||
str = str.replace(/(?:<\d+>|\r)/g, '')
|
||||
let tlyric = []
|
||||
let lyric = str.replace(/\[[\d:.]+\].*?\n\[x-trans\].*/g, s => {
|
||||
// console.log(s)
|
||||
let [lrc, tlrc] = s.split('\n')
|
||||
tlrc = tlrc.replace('[x-trans]', lrc.replace(/^(\[[\d:.]+\]).*$/, '$1'))
|
||||
tlyric.push(tlrc)
|
||||
return lrc
|
||||
})
|
||||
tlyric = tlyric.join('\n')
|
||||
return {
|
||||
lyric,
|
||||
tlyric,
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
failTime: 0,
|
||||
expireTime: 60 * 1000 * 1000,
|
||||
@@ -13,7 +30,10 @@ export default {
|
||||
requestObj.cancelHttp = tryRequestObj.cancelHttp.bind(tryRequestObj)
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
return body
|
||||
return url.endsWith('.xtrc') ? parseLyric(body) : {
|
||||
lyric: body,
|
||||
tlyric: '',
|
||||
}
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
@@ -27,7 +47,10 @@ export default {
|
||||
},
|
||||
}, function(err, resp, body) {
|
||||
if (err || resp.statusCode !== 200) return this.getLyricFile(url, ++retryNum).then(resolve).catch(reject)
|
||||
return resolve(body)
|
||||
return resolve(url.endsWith('.xtrc') ? parseLyric(body) : {
|
||||
lyric: body,
|
||||
tlyric: '',
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
@@ -47,8 +70,12 @@ export default {
|
||||
return tryRequestObj.promise
|
||||
}
|
||||
if (!body.result.data.lyrics.length) return Promise.reject(new Error('未找到歌词'))
|
||||
let lrc = body.result.data.lyrics.find(lyric => /\.lrc$/.test(lyric.lyricUrl))
|
||||
return lrc ? lrc.content : Promise.reject(new Error('未找到歌词'))
|
||||
let lrc = body.result.data.lyrics.find(lyric => /\.(trc|lrc)$/.test(lyric.lyricUrl))
|
||||
return lrc
|
||||
? lrc.lyricUrl.endsWith('.trc')
|
||||
? parseLyric(lrc.content)
|
||||
: { lyric: lrc.content, tlyric: '' }
|
||||
: Promise.reject(new Error('未找到歌词'))
|
||||
})
|
||||
return requestObj
|
||||
},
|
||||
@@ -74,7 +101,7 @@ export default {
|
||||
return requestObj
|
||||
},
|
||||
getLyric(songInfo) {
|
||||
if (songInfo.lrcUrl && /\.lrc$/.test(songInfo.lrcUrl)) return this.getLyricFile_1(songInfo.lrcUrl)
|
||||
if (songInfo.lrcUrl && /\.(xtrc|lrc)$/.test(songInfo.lrcUrl)) return this.getLyricFile_1(songInfo.lrcUrl)
|
||||
return Date.now() - this.failTime > this.expireTime ? this.getLyricUrl_1(songInfo) : this.getLyricUrl_2(songInfo)
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user