- 撤销 3381e9b/1b972ec 中 jx/5s/bl/ap 四个短码,恢复 joox/5sing/bili/apple; qian→bd、migu→mg 保留 - 目录与文件对齐保留的新 id:sdk/qian/→sdk/bd/、sdk/migu/→sdk/mg/、 sdk/apis/qian.ts→bd.ts、migu.ts→mg.ts、src/http/migu-stream.ts→mg-stream.ts (规则改为「目录=对外 id」,聚合入口的模块变量同步更名;music.migu.cn 等域名、 上游 music-lib 对照注释、miguGet 等功能标识符不动) - 对外 id 全表:kw kg tx wy qs xm me qt lr mg bd joox 5sing bili apple **破坏性变更**:joox/5sing/bili/apple 四平台的 URL、/sources 返回与 data/auth.json 凭据键恢复全名,已存短码键的登录态需重新登录。 验证:typecheck ✓、pnpm test 112/112 ✓
43 lines
1.8 KiB
TypeScript
43 lines
1.8 KiB
TypeScript
// 咪咕歌词 —— resourceinfo.do 取 lrcUrl/lyricUrl 再下载文本
|
||
// 上游对应:music-lib/migu/lyric.go
|
||
import { buildUrl, fetchSongDetail, miguGet } from './util.ts'
|
||
import { httpFetch } from '../common/request.ts'
|
||
|
||
const LRC_REFERER = 'https://y.migu.cn/'
|
||
const LRC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36'
|
||
|
||
/** 从 songmid(contentId|resourceType|formatType)或 extra 取 contentId */
|
||
export const contentIdOf = (songInfo: any): string => {
|
||
const extra = songInfo?.extra ?? {}
|
||
if (extra.content_id) return String(extra.content_id)
|
||
const id = String(songInfo?.songmid ?? songInfo?.id ?? '')
|
||
return id.split('|')[0] ?? ''
|
||
}
|
||
|
||
export const getLyric = (songInfo: any) => {
|
||
const requestObj = { cancelHttp() {}, promise: null as any }
|
||
const contentID = contentIdOf(songInfo)
|
||
requestObj.promise = (async() => {
|
||
if (!contentID) throw new Error('migu 歌曲 id 无效')
|
||
const body = await miguGet(buildUrl('http://c.musicapp.migu.cn/MIGUM2.0/v1.0/content/resourceinfo.do', {
|
||
resourceId: contentID,
|
||
resourceType: '2',
|
||
}))
|
||
const resource = body?.resource ?? []
|
||
if (!resource.length) throw new Error('migu 歌词资源不存在')
|
||
let lrcUrl = String(resource[0]?.lrcUrl ?? '') || String(resource[0]?.lyricUrl ?? '')
|
||
if (!lrcUrl) return { lyric: '', tlyric: '' }
|
||
lrcUrl = lrcUrl.replace(/^http:\/\//, 'https://')
|
||
const { statusCode, body: lrc } = await httpFetch(lrcUrl, {
|
||
headers: { 'User-Agent': LRC_UA, Referer: LRC_REFERER },
|
||
timeout: 20000,
|
||
}).promise
|
||
if (statusCode !== 200) throw new Error(`migu 歌词下载失败 ${statusCode}`)
|
||
return { lyric: typeof lrc === 'string' ? lrc : '', tlyric: '' }
|
||
})()
|
||
return requestObj
|
||
}
|
||
|
||
export { fetchSongDetail }
|
||
export default { getLyric }
|