diff --git a/server/glob.d.ts b/server/glob.d.ts index 19904b2..70be7f5 100644 --- a/server/glob.d.ts +++ b/server/glob.d.ts @@ -13,6 +13,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' { export const hackernews: typeof import('./sources/hackernews') export const ithome: typeof import('./sources/ithome') export const kaopu: typeof import('./sources/kaopu') + export const kuaishou: typeof import('./sources/kuaishou') export const producthunt: typeof import('./sources/producthunt') export const solidot: typeof import('./sources/solidot') export const sputniknewscn: typeof import('./sources/sputniknewscn') diff --git a/server/sources/kuaishou.ts b/server/sources/kuaishou.ts new file mode 100644 index 0000000..558c8e3 --- /dev/null +++ b/server/sources/kuaishou.ts @@ -0,0 +1,63 @@ +interface KuaishouRes { + defaultClient: { + ROOT_QUERY: { + "visionHotRank({\"page\":\"home\"})": { + type: string + id: string + typename: string + } + [key: string]: any + } + [key: string]: any + } +} + +interface HotRankData { + result: number + pcursor: string + webPageArea: string + items: { + type: string + generated: boolean + id: string + typename: string + }[] +} + +export default defineSource(async () => { + // 获取快手首页HTML + const html = await $fetch("https://www.kuaishou.com/?isHome=1") + // 提取window.__APOLLO_STATE__中的数据 + const matches = (html as string).match(/window\.__APOLLO_STATE__\s*=\s*(\{.+?\});/) + if (!matches) { + throw new Error("无法获取快手热榜数据") + } + + // 解析JSON数据 + const data: KuaishouRes = JSON.parse(matches[1]) + + // 获取热榜数据ID + const hotRankId = data.defaultClient.ROOT_QUERY["visionHotRank({\"page\":\"home\"})"].id + + // 获取热榜列表数据 + const hotRankData = data.defaultClient[hotRankId] as HotRankData + // 转换数据格式 + return hotRankData.items.map((item) => { + // 从id中提取实际的热搜词 + const hotSearchWord = item.id.replace("VisionHotRankItem:", "") + + // 获取具体的热榜项数据 + const hotItem = data.defaultClient[item.id] + + return { + id: hotSearchWord, + title: hotItem.name, + url: `https://www.kuaishou.com/search/video?searchKey=${encodeURIComponent(hotItem.name)}`, + extra: hotItem.iconUrl + ? { + icon: `/api/proxy?img=${encodeURIComponent(hotItem.iconUrl)}`, + } + : {}, + } + }) +}) diff --git a/shared/sources.ts b/shared/sources.ts index d782892..a0f5319 100644 --- a/shared/sources.ts +++ b/shared/sources.ts @@ -246,6 +246,13 @@ export const originSources = { }, }, }, + "kuaishou": { + name: "快手", + type: "hottest", + column: "china", + color: "orange", + home: "https://www.kuaishou.com", + }, "kaopu": { name: "靠谱新闻", column: "world",