From 33e8ce30323afc8cdb3d1ed6bc15938d5d63f35b Mon Sep 17 00:00:00 2001 From: Daniel Wykerd Date: Thu, 2 Mar 2023 10:49:12 +0200 Subject: [PATCH] feat(parser): SharedPost Add support for SharedPost in community tab. Related to issue #331 --- src/core/Feed.ts | 3 ++- src/parser/classes/SharedPost.ts | 36 ++++++++++++++++++++++++++++++++ src/parser/map.ts | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/parser/classes/SharedPost.ts diff --git a/src/core/Feed.ts b/src/core/Feed.ts index cde6e0913..0a1013145 100644 --- a/src/core/Feed.ts +++ b/src/core/Feed.ts @@ -4,6 +4,7 @@ import { concatMemos, InnertubeError } from '../utils/Utils.js'; import type Actions from './Actions.js'; import BackstagePost from '../parser/classes/BackstagePost.js'; +import SharedPost from '../parser/classes/SharedPost.js'; import Channel from '../parser/classes/Channel.js'; import CompactVideo from '../parser/classes/CompactVideo.js'; import GridChannel from '../parser/classes/GridChannel.js'; @@ -100,7 +101,7 @@ class Feed { * Get all the community posts in the feed */ get posts() { - return this.#memo.getType([ BackstagePost, Post ]); + return this.#memo.getType([ BackstagePost, Post, SharedPost ]); } /** diff --git a/src/parser/classes/SharedPost.ts b/src/parser/classes/SharedPost.ts new file mode 100644 index 000000000..e536b44b3 --- /dev/null +++ b/src/parser/classes/SharedPost.ts @@ -0,0 +1,36 @@ +import { YTNode } from '../helpers.js'; +import Author from './misc/Author.js'; +import { YTNodes } from '../index.js'; +import Parser from '../parser.js'; +import Thumbnail from './misc/Thumbnail.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; +import Text from './misc/Text.js'; + +class SharedPost extends YTNode { + static type = 'SharedPost'; + + thumbnail: Thumbnail[]; + content: Text; + published: Text; + menu: YTNodes.Menu | null; + original_post: YTNodes.BackstagePost | null; + id: string; + endpoint: NavigationEndpoint; + expand_button: YTNodes.Button | null; + author: Author; + + constructor(data: any) { + super(); + this.thumbnail = Thumbnail.fromResponse(data.thumbnail); + this.content = new Text(data.content); + this.published = new Text(data.publishedTimeText); + this.menu = Parser.parseItem(data.actionMenu, [ YTNodes.Menu ]); + this.original_post = Parser.parseItem(data.originalPost, [ YTNodes.BackstagePost ]); + this.id = data.postId; + this.endpoint = new NavigationEndpoint(data.navigationEndpoint); + this.expand_button = Parser.parseItem(data.expandButton, [ YTNodes.Button ]); + this.author = new Author(data.displayName, undefined); + } +} + +export default SharedPost; \ No newline at end of file diff --git a/src/parser/map.ts b/src/parser/map.ts index ecbbe52da..487e5cca3 100644 --- a/src/parser/map.ts +++ b/src/parser/map.ts @@ -528,6 +528,8 @@ import { default as SettingsSidebar } from './classes/SettingsSidebar.js'; export { SettingsSidebar }; import { default as SettingsSwitch } from './classes/SettingsSwitch.js'; export { SettingsSwitch }; +import { default as SharedPost } from './classes/SharedPost.js'; +export { SharedPost }; import { default as Shelf } from './classes/Shelf.js'; export { Shelf }; import { default as ShowingResultsFor } from './classes/ShowingResultsFor.js'; @@ -912,6 +914,7 @@ const map: Record = { SettingsOptions, SettingsSidebar, SettingsSwitch, + SharedPost, Shelf, ShowingResultsFor, SimpleCardContent,