refactor(api)!: 平台 id 收尾统一——migu→mg、apple→ap

补上最后两个多字母 id,至此 15 个平台对外 id 全部为两字母:
kw kg tx wy qs xm me qt lr mg bd jx bl 5s ap

**破坏性变更**:id 出现在所有 URL、/sources 返回以及 data/auth.json 的
凭据键里,咪咕与 Apple Music 已存的登录态会失效,需重新登录。

- sdk/index.ts:id 与 supportQuality 映射键(展示名 `咪咕音乐` /
  `Apple Music` 保持不动)
- sdk/types.ts:Source 联合类型
- src/routes.ts:/stream 的 enum ['qs','migu'] → ['qs','mg'],以及
  /url/mg、/stream/mg 等路径与 schema 描述
- src/http/migu-stream.ts、src/routes-login.ts、src/server.ts
- test/smoke-test.ts、README.md、docs/API.md 同步

有意未改:域名与 API 路径(music.migu.cn、music.apple.com、
amp-api.music.apple.com、/v1/catalog/cn/apple-curators/…)、
标识符(registerMiguStream、appleAmpGet、APPLE_AMP_API_URL 等)、
sdk/migu 与 sdk/apple 的目录与文件名、错误文案里的平台名。

验证:typecheck ✓、pnpm test 112/112 ✓;另起临时实例实证 /sources
(15/15 平台 id 与展示名全对)与 /login/status,旧 id 零残留。
This commit is contained in:
snowy-yang committed 2026-10-03 11:07:21 +08:00
1 parent 3381e9b906
commit 1b972ec4dd
20 files changed
+106 -106

No files matched your search

+26 -26
View File
@@ -514,9 +514,9 @@ await test('专辑详情 /album/lr', async() => {
return `${r.data.info.total} 节`
})
// ---- 新平台(migu/bd/jx/bl/5s/apple 移植回归) ----
// ---- 新平台(migu/bd/jx/bl/5s/ap 移植回归) ----
for (const source of ['migu', 'bd', 'jx', 'bl', '5s', 'apple']) {
for (const source of ['mg', 'bd', 'jx', 'bl', '5s', 'ap']) {
await test(`搜索 ${source} 直查`, async() => {
const r = await get(`/search/${source}/${encodeURIComponent(source === '5s' ? '董贞' : '周杰伦')}?limit=5`)
if (r.code != 0) throw new Error(r.msg)
@@ -525,14 +525,14 @@ for (const source of ['migu', 'bd', 'jx', 'bl', '5s', 'apple']) {
})
}
await test('URL migu(多档候选链)', async() => {
const r = await get(`/search/migu/${encodeURIComponent('起风了')}?limit=3`)
await test('URL mg(多档候选链)', async() => {
const r = await get(`/search/mg/${encodeURIComponent('起风了')}?limit=3`)
if (r.code != 0 || !r.data?.list?.length) throw new Error('搜索失败,无法取流')
const song = r.data.list.find((s: any) => !s.payPlay) ?? r.data.list[0]
const u = await get(`/url/migu/${encodeURIComponent(song.songmid)}?quality=128k`)
const u = await get(`/url/mg/${encodeURIComponent(song.songmid)}?quality=128k`)
if (u.code != 0) throw new Error(u.msg)
const url = String(u.data.url)
if (!url.startsWith('http') && !url.includes('/stream/migu/')) throw new Error('url 非法')
if (!url.startsWith('http') && !url.includes('/stream/mg/')) throw new Error('url 非法')
return `实际 ${u.data.type},${url.slice(0, 60)}`
})
@@ -555,11 +555,11 @@ await test('URL 5s(档位 sq/hq/lq)', async() => {
return `实际 ${u.data.type},${String(u.data.url).slice(0, 60)}`
})
await test('歌词 migu', async() => {
const r = await get(`/search/migu/${encodeURIComponent('起风了')}?limit=3`)
await test('歌词 mg', async() => {
const r = await get(`/search/mg/${encodeURIComponent('起风了')}?limit=3`)
const song = r.data?.list?.[0]
if (!song) throw new Error('搜索失败')
const l = await get(`/lyric/migu/${encodeURIComponent(song.songmid)}`)
const l = await get(`/lyric/mg/${encodeURIComponent(song.songmid)}`)
if (l.code != 0) throw new Error(l.msg)
if (!l.data?.lyric) throw new Error('空歌词')
return l.data.lyric.slice(0, 40)
@@ -575,17 +575,17 @@ await test('歌词 5s', async() => {
return l.data.lyric.slice(0, 40)
})
await test('封面 migu', async() => {
const r = await get(`/search/migu/${encodeURIComponent('起风了')}?limit=3`)
await test('封面 mg', async() => {
const r = await get(`/search/mg/${encodeURIComponent('起风了')}?limit=3`)
const song = r.data?.list?.[0]
if (!song) throw new Error('搜索失败')
const p = await get(`/pic/migu/${encodeURIComponent(song.songmid)}`)
const p = await get(`/pic/mg/${encodeURIComponent(song.songmid)}`)
if (p.code != 0) throw new Error(p.msg)
if (!String(p.data?.url ?? '').startsWith('http')) throw new Error('封面 url 非法')
return String(p.data.url).slice(0, 60)
})
for (const source of ['migu', 'bd', 'jx', 'apple']) {
for (const source of ['mg', 'bd', 'jx', 'ap']) {
await test(`专辑搜索 /album/${source}/search`, async() => {
const r = await get(`/album/${source}/search/${encodeURIComponent('Hello')}?limit=3`)
if (r.code != 0) throw new Error(r.msg)
@@ -594,17 +594,17 @@ for (const source of ['migu', 'bd', 'jx', 'apple']) {
})
}
await test('专辑详情 /album/migu', async() => {
const r = await get(`/search/migu/${encodeURIComponent('起风了')}?limit=3`)
await test('专辑详情 /album/mg', async() => {
const r = await get(`/search/mg/${encodeURIComponent('起风了')}?limit=3`)
const albumId = r.data?.list?.find((s: any) => s.albumId)?.albumId
if (!albumId) throw new Error('搜索结果未携带 albumId')
const a = await get(`/album/migu/${albumId}`)
const a = await get(`/album/mg/${albumId}`)
if (a.code != 0) throw new Error(a.msg)
if (!a.data?.list?.length) throw new Error('专辑无曲目')
return `${a.data.info.name}(${a.data.total} 首)`
})
for (const source of ['migu', 'bd', 'jx', 'apple']) {
for (const source of ['mg', 'bd', 'jx', 'ap']) {
await test(`歌单分类 /playlist/${source}/categories`, async() => {
const r = await get(`/playlist/${source}/categories`)
if (r.code != 0) throw new Error(r.msg)
@@ -623,13 +623,13 @@ for (const source of ['migu', 'bd', 'jx', 'apple']) {
})
}
await test('歌单详情 /playlist/migu', async() => {
const c = await get('/playlist/migu/categories')
await test('歌单详情 /playlist/mg', async() => {
const c = await get('/playlist/mg/categories')
const cat = c.data.list[0]
const pl = await get(`/playlist/migu/categories/${encodeURIComponent(cat.id)}?limit=3`)
const pl = await get(`/playlist/mg/categories/${encodeURIComponent(cat.id)}?limit=3`)
const id = pl.data?.list?.[0]?.id
if (!id) throw new Error('未取到歌单 id')
const d = await get(`/playlist/migu/${id}?limit=5`)
const d = await get(`/playlist/mg/${id}?limit=5`)
if (d.code != 0) throw new Error(d.msg)
if (!d.data?.list?.length) throw new Error('歌单无曲目')
return `${d.data.total} 首,本页 ${d.data.list.length} 首`
@@ -645,8 +645,8 @@ await test('歌单详情 /playlist/bl(合集)', async() => {
return `${d.data.total} 首`
})
await test('链接解析 /parse/song/migu', async() => {
const r = await postJson('/parse/song/migu', { link: 'https://music.migu.cn/v3/music/song/600913000002601091' })
await test('链接解析 /parse/song/mg', async() => {
const r = await postJson('/parse/song/mg', { link: 'https://music.migu.cn/v3/music/song/600913000002601091' })
if (r.status !== 200 || r.body?.code != 0) throw new Error(JSON.stringify(r.body).slice(0, 120))
if (!r.body.data?.song?.songmid) throw new Error('缺少 song')
return `${r.body.data.song.name} / ${r.body.data.song.singer}`
@@ -659,8 +659,8 @@ await test('链接解析 /parse/playlist/bd', async() => {
return `${r.body.data.playlist?.name ?? ''}(${r.body.data.total} 首)`
})
await test('链接解析 /parse/album/apple', async() => {
const r = await postJson('/parse/album/apple', { link: 'https://music.apple.com/us/album/the-life-of-a-showgirl-the-encore/6814997249' })
await test('链接解析 /parse/album/ap', async() => {
const r = await postJson('/parse/album/ap', { link: 'https://music.apple.com/us/album/the-life-of-a-showgirl-the-encore/6814997249' })
if (r.status !== 200 || r.body?.code != 0) throw new Error(JSON.stringify(r.body).slice(0, 120))
if (!r.body.data?.list?.length) throw new Error('无曲目')
return `${r.body.data.playlist?.name ?? ''}(${r.body.data.total} 首)`
@@ -705,7 +705,7 @@ await test('个人歌单 未支持的平台 → 502', async() => {
})
await test('咪咕解密流代理 无票据 → 404', async() => {
const r = await getRaw('/stream/migu/ffffffffffffffffffffffffffffffff')
const r = await getRaw('/stream/mg/ffffffffffffffffffffffffffffffff')
if (r.status !== 404) throw new Error(`期望 404,实际 ${r.status}`)
return JSON.parse(r.body).msg?.slice(0, 50)
})