mirror of
https://github.com/ourongxing/newsnow.git
synced 2025-01-31 19:08:05 +08:00
feat(source): add kuaishou (#7)
* feat(source): add kuaishou * Update kuaishou.ts * Update sources.ts --------- Co-authored-by: Ou <orongxing@gmail.com>
This commit is contained in:
parent
769f127a78
commit
9d2dc242d1
1
server/glob.d.ts
vendored
1
server/glob.d.ts
vendored
@ -13,6 +13,7 @@ declare module 'glob:./sources/{*.ts,**/index.ts}' {
|
|||||||
export const hackernews: typeof import('./sources/hackernews')
|
export const hackernews: typeof import('./sources/hackernews')
|
||||||
export const ithome: typeof import('./sources/ithome')
|
export const ithome: typeof import('./sources/ithome')
|
||||||
export const kaopu: typeof import('./sources/kaopu')
|
export const kaopu: typeof import('./sources/kaopu')
|
||||||
|
export const kuaishou: typeof import('./sources/kuaishou')
|
||||||
export const producthunt: typeof import('./sources/producthunt')
|
export const producthunt: typeof import('./sources/producthunt')
|
||||||
export const solidot: typeof import('./sources/solidot')
|
export const solidot: typeof import('./sources/solidot')
|
||||||
export const sputniknewscn: typeof import('./sources/sputniknewscn')
|
export const sputniknewscn: typeof import('./sources/sputniknewscn')
|
||||||
|
63
server/sources/kuaishou.ts
Normal file
63
server/sources/kuaishou.ts
Normal file
@ -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)}`,
|
||||||
|
}
|
||||||
|
: {},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
@ -246,6 +246,13 @@ export const originSources = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"kuaishou": {
|
||||||
|
name: "快手",
|
||||||
|
type: "hottest",
|
||||||
|
column: "china",
|
||||||
|
color: "orange",
|
||||||
|
home: "https://www.kuaishou.com",
|
||||||
|
},
|
||||||
"kaopu": {
|
"kaopu": {
|
||||||
name: "靠谱新闻",
|
name: "靠谱新闻",
|
||||||
column: "world",
|
column: "world",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user