对外 id 统一为两字母短码,与既有的 kw/kg/tx/wy/qs/xm/me/qt/lr 对齐; migu 与 apple 保持原样(Apple Music 没有自然的短码)。 **破坏性变更**:id 出现在所有 URL、/sources 返回、OpenAPI 示例以及 data/auth.json 的凭据键里,这四个平台已存的登录态会失效,需重新登录。 - sdk/index.ts:id 与 supportQuality 映射键 - sdk/types.ts:Source 联合类型 - src/routes.ts 与 routes-login.ts:路由路径与 schema 描述 (/login/bili/qr → /login/bl/qr 等)、/login/status 的响应键 - test/smoke-test.ts、README.md、docs/API.md 同步 有意未改:sdk 目录与文件名仍用平台名(sdk/qian/、sdk/apis/joox.ts …), 规则定为「目录=平台名,id=对外短码」,映射只在 SUPPORTED_SOURCES 一处声明。 域名与正则(joox.com、5sing.kugou.com、/joox\.com\//)、jooxSign 等标识符、 错误文案里的中文平台名、以及 kg 榜单名(含「joox本地热歌榜」)全部保持原样—— 它们只是恰好含平台名,并不是 id。 验证:typecheck ✓、pnpm test 112/112 ✓;另起临时实例实证 /sources 与 /login/status 的新 id 与展示名,新旧 id 均无残留。
74 lines
2.5 KiB
TypeScript
74 lines
2.5 KiB
TypeScript
// JOOX 歌曲形状映射(统一 Song 形状,见 tmp/port-spec.md)
|
||
// 兼容来源:openjoox2 track/album/playlist 条目、openjoox v3 search 的 song_info、
|
||
// 以及 SSR 页面上的 track 条目(字段有 snake/camel 两套命名,上游 Go 也两套都兜底)。
|
||
|
||
import { formatPlayTime } from '../common/utils.ts'
|
||
import {
|
||
normalizeJooxID,
|
||
pickJooxImage,
|
||
jooxArtists,
|
||
firstNonEmpty,
|
||
firstNonZero,
|
||
} from './util.ts'
|
||
|
||
/** 详情/列表 track 条目 → 统一 Song 形状 */
|
||
export const jooxSongFromTrack = (
|
||
item: any,
|
||
fallbackAlbum = '',
|
||
fallbackCover = '',
|
||
fallbackAlbumId = '',
|
||
): any | null => {
|
||
const songmid = normalizeJooxID(item?.id)
|
||
if (!songmid) return null
|
||
|
||
const artists = Array.isArray(item?.artist_list) && item.artist_list.length
|
||
? item.artist_list
|
||
: item?.artistList
|
||
const albumId = normalizeJooxID(firstNonEmpty(item?.album_id, item?.albumId, fallbackAlbumId))
|
||
|
||
return {
|
||
songmid,
|
||
name: String(firstNonEmpty(item?.name, item?.title, 'Unknown')),
|
||
singer: String(firstNonEmpty(jooxArtists(artists), 'Unknown')),
|
||
albumId: String(albumId || ''),
|
||
albumName: String(firstNonEmpty(item?.album_name, item?.albumName, fallbackAlbum)),
|
||
interval: formatPlayTime(firstNonZero(item?.play_duration, item?.playDuration, item?.duration)),
|
||
img: String(firstNonEmpty(
|
||
pickJooxImage(item?.images),
|
||
item?.imgSrc,
|
||
item?.cover,
|
||
item?.image,
|
||
item?.pic,
|
||
fallbackCover,
|
||
)) || null,
|
||
lrc: null,
|
||
vip: Number(item?.vip_flag ?? 0) === 1,
|
||
types: [],
|
||
_types: {},
|
||
source: 'jx' as const,
|
||
}
|
||
}
|
||
|
||
/** openjoox v3 搜索歌曲条目(song_info)→ 统一 Song 形状 */
|
||
export const jooxSongFromSearch = (info: any): any | null => jooxSongFromTrack(info)
|
||
|
||
/** 详情接口返回的整曲信息(parse 用,含可播放地址)→ 统一 Song 形状 */
|
||
export const jooxSongFromDetail = (detail: any, playUrl = ''): any => {
|
||
const song = jooxSongFromTrack(detail) ?? {
|
||
songmid: normalizeJooxID(detail?.id),
|
||
name: String(detail?.name ?? ''),
|
||
singer: String(jooxArtists(detail?.artist_list)),
|
||
albumId: String(normalizeJooxID(detail?.album_id)),
|
||
albumName: String(detail?.album_name ?? ''),
|
||
interval: formatPlayTime(firstNonZero(detail?.play_duration)),
|
||
img: String(pickJooxImage(detail?.images)) || null,
|
||
lrc: null,
|
||
types: [],
|
||
_types: {},
|
||
source: 'jx' as const,
|
||
}
|
||
if (playUrl) song.url = playUrl
|
||
song.vip = Number(detail?.vip_flag ?? 0) === 1
|
||
return song
|
||
}
|