From 61ab51687fb79c041b10be4bc2fe050222d0ae82 Mon Sep 17 00:00:00 2001 From: the1812 Date: Wed, 30 Aug 2023 21:38:06 +0800 Subject: [PATCH] Upgrade getVideoFeeds API (#4305) --- src/components/feeds/VideoCard.vue | 2 +- src/components/feeds/api/index.ts | 93 ++++++++++++++++-------------- src/components/feeds/video-card.ts | 1 + 3 files changed, 53 insertions(+), 43 deletions(-) diff --git a/src/components/feeds/VideoCard.vue b/src/components/feeds/VideoCard.vue index 111c5f4a2..844320cdb 100644 --- a/src/components/feeds/VideoCard.vue +++ b/src/components/feeds/VideoCard.vue @@ -38,7 +38,7 @@ :title="topic.name" class="topic" target="_blank" - :href="'https://t.bilibili.com/topic/name/' + topic.name + '/feed'" + :href="topic.url || 'https://t.bilibili.com/topic/name/' + topic.name + '/feed'" >
diff --git a/src/components/feeds/api/index.ts b/src/components/feeds/api/index.ts index 2fc662cf4..27e4078ff 100644 --- a/src/components/feeds/api/index.ts +++ b/src/components/feeds/api/index.ts @@ -1,6 +1,6 @@ import { getUID, pascalCase } from '@/core/utils' import { getJsonWithCredentials } from '@/core/ajax' -import { formatCount, formatDuration } from '@/core/utils/formatters' +import { formatCount, formatDuration, parseDuration } from '@/core/utils/formatters' import { watchlaterList } from '@/components/video/watchlater' import { getData, registerData } from '@/plugins/data' import { descendingStringSort } from '@/core/utils/sort' @@ -104,59 +104,68 @@ export const getVideoFeeds = withContentFilter( if (json.code !== 0) { throw new Error(json.message) } - const dataCards = json.data.cards as any[] - const dataCardsWithoutPreOrder = dataCards.filter(it => !isPreOrderedVideo(JSON.parse(it.card))) + const dataCards = json.data.items as any[] if (type === 'video') { return groupVideoFeeds( - dataCards.map((c: any): VideoCard => { - const card = JSON.parse(c.card) - const topics = lodash.get(c, 'display.topic_info.topic_details', []).map((it: any) => ({ - id: it.topic_id, - name: it.topic_name, - })) + dataCards.map((card: any): VideoCard => { + const archive = lodash.get(card, 'modules.module_dynamic.major.archive') + const author = lodash.get(card, 'modules.module_author') + const dynamic = lodash.get(card, 'modules.module_dynamic.desc.text', '') + const stat = lodash.get(card, 'modules.module_stat') + const topics = ( + lodash.get(card, 'modules.module_dynamic.desc.rich_text_nodes', []) as any[] + ) + .filter(node => node.type === 'RICH_TEXT_NODE_TYPE_TOPIC') + .map(node => { + return { + id: node.text, + name: node.text, + url: node.jump_url, + } + }) return { - id: c.desc.dynamic_id_str, - aid: card.aid, - bvid: c.desc.bvid || card.bvid, - title: card.title, - upID: c.desc.user_profile.info.uid, - upName: c.desc.user_profile.info.uname, - upFaceUrl: c.desc.user_profile.info.face, - coverUrl: card.pic, - description: card.desc, - timestamp: c.timestamp, - time: new Date(c.timestamp * 1000), + id: card.id_str, + aid: archive.aid, + bvid: archive.bvid, + title: archive.title, + upFaceUrl: author.face, + upName: author.name, + upID: author.mid, + coverUrl: archive.cover, + description: archive.desc, + timestamp: author.pub_ts * 1000, + time: new Date(author.pub_ts * 1000), topics, - dynamic: card.dynamic, - like: formatCount(c.desc.like), - duration: card.duration, - durationText: formatDuration(card.duration, 0), - playCount: formatCount(card.stat.view), - danmakuCount: formatCount(card.stat.danmaku), - watchlater: watchlaterList.includes(card.aid), + dynamic, + like: formatCount(stat.like.count), + duration: parseDuration(archive.duration_text), + durationText: formatDuration(parseDuration(archive.duration_text)), + playCount: formatCount(archive.stat.play), + danmakuCount: formatCount(archive.stat.danmaku), + watchlater: watchlaterList.includes(archive.aid), } }), ) } if (type === 'bangumi') { - return dataCardsWithoutPreOrder.map((c: any): VideoCard => { - const card = JSON.parse(c.card) + return dataCards.map((card: any): VideoCard => { + const pgc = lodash.get(card, 'modules.module_dynamic.major.pgc') + const author = lodash.get(card, 'modules.module_author') + const stat = lodash.get(card, 'modules.module_stat') return { - id: c.desc.dynamic_id_str, - aid: card.aid, - bvid: c.desc.bvid || card.bvid, - epID: card.episode_id, - title: card.new_desc, - upName: card.apiSeasonInfo.title, - upFaceUrl: card.apiSeasonInfo.cover, - coverUrl: card.cover, + id: card.id_str, + epID: pgc.epid, + title: pgc.title.replace(new RegExp(`^${author.name}:`), ''), + upName: author.name, + upFaceUrl: author.face, + coverUrl: pgc.cover, description: '', - timestamp: c.timestamp, - time: new Date(c.timestamp * 1000), - like: formatCount(c.desc.like), + timestamp: author.pub_ts * 1000, + time: new Date(author.pub_ts * 1000), + like: formatCount(stat.like.count), durationText: '', - playCount: formatCount(card.play_count), - danmakuCount: formatCount(card.bullet_count), + playCount: formatCount(pgc.stat.play), + danmakuCount: formatCount(pgc.stat.danmaku), watchlater: false, } }) diff --git a/src/components/feeds/video-card.ts b/src/components/feeds/video-card.ts index 42ca15b96..282eb1a76 100644 --- a/src/components/feeds/video-card.ts +++ b/src/components/feeds/video-card.ts @@ -23,6 +23,7 @@ export interface VideoCard { topics?: { id: number name: string + url?: string }[] type?: string points?: number