feat(album): 新增 QQ 音乐(tx)专辑支持

This commit is contained in:
snowy-yang committed 2026-09-17 06:20:37 +08:00
1 parent b06769dbbd
commit 0f2585e5bd
7 files changed
+88 -33

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { filterMusicInfoItem } from './singer.ts'
import { createMusicuFetch } from './utils/index.ts'
export default {
/**
* 通过专辑 mid 获取专辑详情与曲目列表
* @param {*} id 专辑 mid(搜索结果中的 albumId)
* @param {*} page
* @param {*} limit
*/
async getAlbumDetail(id, page = 1, limit = 100) {
const body = await createMusicuFetch({
req: {
module: 'music.musichallAlbum.AlbumSongList',
method: 'GetAlbumSongList',
// 注意:参数名是驼峰 albumMid,下划线形态会被上游以 104400 拒绝
param: { albumMid: id, begin: (page - 1) * limit, num: limit },
},
})
if (body.req.code != 0) throw new Error('get album song list faild.')
const data = body.req.data
const songList = data.songList ?? []
// GetAlbumInfo 详情接口已停用:专辑名取自曲目自带的 album 信息,
// 作者由曲目歌手去重合成,封面用平台固定图片 URL 规则
const first = songList[0]?.songInfo
const authors = [...new Set(songList.flatMap(item => item.songInfo?.singer?.map(s => s.name) ?? []))]
return {
source: 'tx',
info: {
name: first?.album?.name ?? null,
img: `https://y.gtimg.cn/music/photo_new/T002R500x500M000${id}.jpg`,
desc: null,
author: authors.join('、') || null,
},
list: this.filterSongList(songList),
page,
limit,
total: data.totalNum,
}
},
filterSongList(raw) {
return (raw ?? []).map(item => filterMusicInfoItem(item.songInfo))
},
}
+2
View File
@@ -6,6 +6,7 @@ import { apis } from '../api-source.ts'
import hotSearch from './hotSearch.ts'
import comment from './comment.ts'
import singer from './singer.ts'
import album from './album.ts'
// import tipSearch from './tipSearch.ts'
const tx = {
@@ -16,6 +17,7 @@ const tx = {
hotSearch,
comment,
singer,
album,
getMusicUrl(songInfo, type) {
return apis('tx')!.getMusicUrl(songInfo, type)
+4 -31
View File
@@ -1,8 +1,8 @@
import type { HttpRequestObject, SongType, Quality, QualityInfo } from '../types.ts'
import { httpFetch } from '../request.ts'
import type { SongType, Quality, QualityInfo } from '../types.ts'
import { formatPlayTime, sizeFormate } from '../index.ts'
import { formatSingerName } from '../utils.ts'
import { createMusicuFetch } from './utils/index.ts'
export const filterMusicInfoItem = item => {
const types: SongType[] = []
@@ -60,35 +60,8 @@ export const filterMusicInfoItem = item => {
}
/**
* musicu.fcg 通用请求(comm 参数对齐榜单模块的可用配置)。
* 注意:musichallSinger.GetSingerDetail 等歌手详情接口在该通道已停用(104403),
* 歌手名/统计改由歌单与专辑接口合成。
*/
const createMusicuFetch = async(data, retryNum = 0) => {
if (retryNum > 2) throw new Error('try max num')
let result
try {
result = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
method: 'post',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
},
body: {
comm: { uin: 0, format: 'json', ct: 20, cv: 1859 },
...data,
},
}).promise
} catch (err) {
console.log(err)
return createMusicuFetch(data, ++retryNum)
}
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, ++retryNum)
return result.body
}
// 歌手详情接口(musichallSinger.GetSingerDetail 等)已停用(104403):
// 歌手名/统计由 GetSingerSongList 与 GetAlbumList 合成,头像走固定图片 URL 规则
export default {
/**
* 获取歌手信息
+28
View File
@@ -15,3 +15,31 @@ export const signRequest = async(data) => {
body: data,
}).promise
}
/**
* musicu.fcg 通用请求(comm 参数对齐榜单模块的可用配置;
* musichallSinger/musichallAlbum 的部分详情接口在该通道已停用,见各模块说明)
*/
export const createMusicuFetch = async(data, retryNum = 0) => {
if (retryNum > 2) throw new Error('try max num')
let result
try {
result = await httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
method: 'post',
headers: {
'User-Agent': 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)',
},
body: {
comm: { uin: 0, format: 'json', ct: 20, cv: 1859 },
...data,
},
}).promise
} catch (err) {
console.log(err)
return createMusicuFetch(data, ++retryNum)
}
if (result.statusCode !== 200 || result.body.code != 0) return createMusicuFetch(data, ++retryNum)
return result.body
}