Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parser): SharedPost #332

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -100,7 +101,7 @@ class Feed<T extends IParsedResponse = IParsedResponse> {
* Get all the community posts in the feed
*/
get posts() {
return this.#memo.getType<Post | BackstagePost>([ BackstagePost, Post ]);
return this.#memo.getType<Post | BackstagePost | SharedPost>([ BackstagePost, Post, SharedPost ]);
}

/**
Expand Down
36 changes: 36 additions & 0 deletions src/parser/classes/SharedPost.ts
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions src/parser/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -912,6 +914,7 @@ const map: Record<string, YTNodeConstructor> = {
SettingsOptions,
SettingsSidebar,
SettingsSwitch,
SharedPost,
Shelf,
ShowingResultsFor,
SimpleCardContent,
Expand Down