Files
snowy-yang 8c02fb5c15 refactor(sdk): 审计 P2 卫生项清理——请求层收敛与死代码清除
- 删除旧 sdk/request.ts,全部 import 收敛到 sdk/common/request.ts(85 文件)
- 注释死代码 630+ 行、裸 console.log 吞错 6 处、未使用符号 26 处清零
- bili 状态校验去重;utils DNS 预解析失败日志改 warn 带上下文
- CODE-AUDIT.md:第四节 P2 清理记录 + 第八节线索逐条复核结论(kw/kg/tx/wy parse 骨架相似实质各异,不抽公共层)
2026-10-03 20:48:54 +08:00

59 lines
2.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 喜马拉雅专辑曲目列表(免签匿名接口)
// 接口: https://www.ximalaya.com/revision/album/getTracksList?albumId=&pageNum=&sort=0
// 实测(2026-10-02)匿名可翻全部页(固定每页 30 条);仅曲目元信息(trackId/title/isPaid),
// 播放地址需另走 baseInfo。注意 v1 版接口(/revision/album/v1/getTracksList)需要 webtk 签名且有风控。
import { httpFetch } from '../common/request.ts'
import { XM_UA } from './sign.ts'
const TRACKS_URL = 'https://www.ximalaya.com/revision/album/getTracksList'
const PAGE_SIZE = 30
/** 抓取专辑第 pageNum 页曲目(返回 { total, tracks }) */
export const getTracksPage = async(albumId: string, pageNum: number) => {
const { statusCode, body } = await httpFetch(`${TRACKS_URL}?albumId=${albumId}&pageNum=${pageNum}&sort=0`, {
headers: { 'User-Agent': XM_UA, Referer: `https://www.ximalaya.com/album/${albumId}` },
timeout: 15000,
}).promise as any
if (statusCode != 200 || body?.ret != 200 || !body?.data) {
throw new Error(body?.msg || `获取专辑曲目失败(ret ${body?.ret ?? statusCode})`)
}
return {
total: Number(body.data.trackTotalCount ?? 0),
tracks: body.data.tracks ?? [],
}
}
/** 专辑详情 + 指定页曲目(/album 路由适配:{ info, list },接口固定每页 30 条) */
export const getAlbumDetail = async(albumId: string, page = 1, limit = 30) => {
const { total, tracks } = await getTracksPage(albumId, page)
let albumName = ''
const list = tracks.slice(0, limit).map((item: any) => {
if (!albumName && item.albumTitle) albumName = String(item.albumTitle)
return {
songmid: String(item.trackId),
name: item.title || String(item.trackId),
singer: item.albumTitle || '',
albumId: String(albumId),
albumName: item.albumTitle || '',
interval: 0,
payPlay: Boolean(item.isPaid),
img: null,
lrc: '',
lrcx: '',
types: [],
_types: {},
disabled: false,
}
})
return {
info: { name: albumName || String(albumId), total },
list,
total,
limit,
allPage: Math.ceil(total / PAGE_SIZE) || page,
source: 'xm',
}
}
export default { getTracksPage, getAlbumDetail }