- adapters/meta:bgm.tv 官方 API(条目 / 搜索 / 每日放送)与豆瓣移动版接口(条目 / 实时热门) - 识别升级链:豆瓣条目缓存没有时在线查;AniBT 的 bgm ID、公开 BT 站标题搜 bgm → 名称 + 年份匹配 TMDB(季条目去季名与年份) - 条目缓存 30 天,查不到 6 小时负缓存;测试进程缺省不出外网 - 发现页:bgm 每日放送、豆瓣热门电影 / 剧集,点条目匹配 TMDB 作品 Co-Authored-By: Claude Opus 5.5 <[email protected]>
76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
import { createMockFetch } from "@umt/testkit";
|
|
import { describe, expect, it } from "vitest";
|
|
import { bangumiSubject, createBangumiClient, createDoubanClient, doubanSubject, MetaSourceError } from "./index.ts";
|
|
|
|
// 字段取自 2026-10-02 api.bgm.tv / m.douban.com 实际返回(删减)
|
|
const BGM = {
|
|
id: 400602,
|
|
name: "葬送のフリーレン",
|
|
name_cn: "葬送的芙莉莲",
|
|
date: "2023-09-29",
|
|
platform: "TV",
|
|
total_episodes: 36,
|
|
eps: 28,
|
|
images: { large: "http://lain.bgm.tv/pic/cover/l/13/c5/400602_ZI8Y9.jpg" },
|
|
rating: { score: 8.5 },
|
|
infobox: [
|
|
{ key: "中文名", value: "葬送的芙莉莲" },
|
|
{ key: "别名", value: [{ v: "Frieren: Beyond Journey's End" }, { v: "Sousou no Frieren" }] },
|
|
],
|
|
};
|
|
const DOUBAN_TV = {
|
|
id: "36449295",
|
|
title: "兰香如故",
|
|
original_title: "",
|
|
aka: ["兰香缘"],
|
|
year: "2026",
|
|
type: "tv",
|
|
is_tv: true,
|
|
episodes_count: 47,
|
|
pubdate: ["2026-09-11(中国大陆)"],
|
|
rating: { value: 7.5 },
|
|
pic: { large: "https://img9.doubanio.com/view/photo/m_ratio_poster/public/p2933527614.jpg" },
|
|
};
|
|
|
|
describe("辅助信息源 bgm.tv / 豆瓣", () => {
|
|
it("bgm 条目:中文名优先,原名与别名进 aliases,图片改 https,TV 按剧集", () => {
|
|
expect(bangumiSubject(BGM)).toMatchObject({
|
|
id: "400602",
|
|
title: "葬送的芙莉莲",
|
|
aliases: ["葬送のフリーレン", "Frieren: Beyond Journey's End", "Sousou no Frieren"],
|
|
year: 2023,
|
|
kind: "tv",
|
|
cover: "https://lain.bgm.tv/pic/cover/l/13/c5/400602_ZI8Y9.jpg",
|
|
rating: 8.5,
|
|
episodes: 36,
|
|
});
|
|
expect(bangumiSubject({ ...BGM, platform: "剧场版" })?.kind).toBe("movie");
|
|
});
|
|
|
|
it("豆瓣条目:去掉标题里的方向符,首播日期与类型", () => {
|
|
expect(doubanSubject({ ...DOUBAN_TV, title: "兰香如故" })).toMatchObject({
|
|
title: "兰香如故",
|
|
aliases: ["兰香缘"],
|
|
year: 2026,
|
|
kind: "tv",
|
|
date: "2026-09-11",
|
|
episodes: 47,
|
|
});
|
|
});
|
|
|
|
it("豆瓣详情类型未知:电影接口 404 再查剧集;bgm 带 UA", async () => {
|
|
const m = createMockFetch({
|
|
"GET /rexxar/api/v2/movie/36449295": { status: 404, body: "" },
|
|
"GET /rexxar/api/v2/tv/36449295": { body: DOUBAN_TV },
|
|
"GET https://api.bgm.tv/v0/subjects/400602": { body: BGM },
|
|
});
|
|
const d = createDoubanClient({ fetch: m.fetch });
|
|
expect((await d.subject("36449295")).kind).toBe("tv");
|
|
expect(m.requests[0]!.headers.referer).toBe("https://m.douban.com/");
|
|
const b = createBangumiClient({ fetch: m.fetch });
|
|
expect((await b.subject("400602")).title).toBe("葬送的芙莉莲");
|
|
expect(m.requests.at(-1)!.headers["user-agent"]).toContain("uhd-media-tool");
|
|
await expect(b.subject("abc")).rejects.toBeInstanceOf(MetaSourceError);
|
|
});
|
|
});
|