mirror of
https://github.com/ZHANGTIANYAO1/teamspeak-music-bot.git
synced 2026-10-02 04:52:50 +08:00
feat(netease): include albums in search results
Add mapNeteaseAlbums pure helper and wire cloudsearch?type=10 as the third Promise.all arm in search(), replacing the hardcoded albums:[]. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
ff5502be2f
commit
a2453784c1
2 files changed
+49
-3
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { parseLyrics } from "./netease.js";
|
||||
import { parseLyrics, mapNeteaseAlbums } from "./netease.js";
|
||||
|
||||
describe("NetEase adapter", () => {
|
||||
it("parses LRC format lyrics", () => {
|
||||
@@ -28,4 +28,32 @@ describe("NetEase adapter", () => {
|
||||
expect(lines[0].text).toBe("Hello world");
|
||||
expect(lines[0].translation).toBe("你好世界");
|
||||
});
|
||||
|
||||
it("mapNeteaseAlbums maps raw cloudsearch albums to Album shape", () => {
|
||||
const raw = [
|
||||
{
|
||||
id: 42,
|
||||
name: "Album A",
|
||||
picUrl: "https://x/p.jpg",
|
||||
artists: [{ name: "Artist X" }, { name: "Featured Y" }],
|
||||
size: 12,
|
||||
},
|
||||
{
|
||||
id: 99,
|
||||
name: "Album B",
|
||||
picUrl: "",
|
||||
artists: [],
|
||||
},
|
||||
];
|
||||
expect(mapNeteaseAlbums(raw)).toEqual([
|
||||
{ id: "42", name: "Album A", artist: "Artist X / Featured Y", coverUrl: "https://x/p.jpg", songCount: 12, platform: "netease" },
|
||||
{ id: "99", name: "Album B", artist: "", coverUrl: "", songCount: 0, platform: "netease" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("mapNeteaseAlbums returns [] for empty/null input", () => {
|
||||
expect(mapNeteaseAlbums([])).toEqual([]);
|
||||
expect(mapNeteaseAlbums(null as any)).toEqual([]);
|
||||
expect(mapNeteaseAlbums(undefined as any)).toEqual([]);
|
||||
});
|
||||
});
|
||||
+20
-2
@@ -8,6 +8,7 @@ import type {
|
||||
SearchResult,
|
||||
QrCodeResult,
|
||||
AuthStatus,
|
||||
Album,
|
||||
} from "./provider.js";
|
||||
|
||||
export function parseLyrics(lrc: string, tlyric?: string): LyricLine[] {
|
||||
@@ -55,6 +56,18 @@ export function parseLyrics(lrc: string, tlyric?: string): LyricLine[] {
|
||||
return lines.sort((a, b) => a.time - b.time);
|
||||
}
|
||||
|
||||
export function mapNeteaseAlbums(raw: any[] | null | undefined): Album[] {
|
||||
if (!Array.isArray(raw)) return [];
|
||||
return raw.map((a) => ({
|
||||
id: String(a.id),
|
||||
name: a.name ?? "",
|
||||
artist: (a.artists ?? []).map((x: any) => x.name).join(" / "),
|
||||
coverUrl: a.picUrl ?? "",
|
||||
songCount: a.size ?? 0,
|
||||
platform: "netease",
|
||||
}));
|
||||
}
|
||||
|
||||
// NetEase quality levels: standard(128k) higher(192k) exhigh(320k) lossless(flac) hires(hi-res) jyeffect jymaster
|
||||
export const NETEASE_QUALITY_LEVELS = [
|
||||
{ value: "standard", label: "标准 (128kbps)", bitrate: 128 },
|
||||
@@ -91,7 +104,7 @@ export class NeteaseProvider implements MusicProvider {
|
||||
}
|
||||
|
||||
async search(query: string, limit = 20): Promise<SearchResult> {
|
||||
const [songRes, playlistRes] = await Promise.all([
|
||||
const [songRes, playlistRes, albumRes] = await Promise.all([
|
||||
this.api.get("/cloudsearch", {
|
||||
params: { keywords: query, type: 1, limit, ...this.cookieParams },
|
||||
}),
|
||||
@@ -103,6 +116,9 @@ export class NeteaseProvider implements MusicProvider {
|
||||
...this.cookieParams,
|
||||
},
|
||||
}),
|
||||
this.api.get("/cloudsearch", {
|
||||
params: { keywords: query, type: 10, limit: 5, ...this.cookieParams },
|
||||
}),
|
||||
]);
|
||||
|
||||
const songs: Song[] = (songRes.data?.result?.songs ?? []).map(
|
||||
@@ -127,7 +143,9 @@ export class NeteaseProvider implements MusicProvider {
|
||||
platform: "netease",
|
||||
}));
|
||||
|
||||
return { songs, playlists, albums: [] };
|
||||
const albums = mapNeteaseAlbums(albumRes.data?.result?.albums);
|
||||
|
||||
return { songs, playlists, albums };
|
||||
}
|
||||
|
||||
async getSongUrl(songId: string, quality?: string): Promise<string | null> {
|
||||
|
||||
Reference in new issue
Block a user