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

fear(parser): Add DecoratedAvatarView #544

Merged
merged 7 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
30 changes: 30 additions & 0 deletions src/parser/classes/AvatarView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { YTNode } from '../helpers.js';
import { type RawNode } from '../index.js';
import { Thumbnail } from '../misc.js';

export default class AvatarView extends YTNode {
static type = 'AvatarView';

image: {
sources: Thumbnail[],
processor: {
border_image_processor: {
circular: boolean
}
}
};
avatar_image_size: string;

constructor(data: RawNode) {
super();
this.image = {
sources: data.image.sources.map((x: any) => new Thumbnail(x)).sort((a: Thumbnail, b: Thumbnail) => b.width - a.width),
processor: {
border_image_processor: {
circular: data.image.processor.borderImageProcessor.circular
}
}
};
this.avatar_image_size = data.avatarImageSize;
}
}
35 changes: 35 additions & 0 deletions src/parser/classes/DecoratedAvatarView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { NavigationEndpoint } from '../nodes.js';
import AvatarView from './AvatarView.js';

export default class DecoratedAvatarView extends YTNode {
static type = 'DecoratedAvatarView';

avatar: {
avatar_view_model: AvatarView
};
a11y_label: string;
renderer_context: {
command_context: {
on_tap: {
innertube_command: NavigationEndpoint
}
}
};

constructor(data: RawNode) {
super();
this.avatar = {
avatar_view_model: new AvatarView(data.avatar.avatarViewModel)
};
this.a11y_label = data.a11yLabel;
this.renderer_context = {
command_context: {
on_tap: {
innertube_command: new NavigationEndpoint(data.rendererContext.commandContext.onTap.innertubeCommand)
}
}
};
}
}
5 changes: 3 additions & 2 deletions src/parser/classes/PageHeaderView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ import { YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import ContentMetadataView from './ContentMetadataView.js';
import ContentPreviewImageView from './ContentPreviewImageView.js';
import DecoratedAvatarView from './DecoratedAvatarView.js';
import DynamicTextView from './DynamicTextView.js';
import FlexibleActionsView from './FlexibleActionsView.js';

export default class PageHeaderView extends YTNode {
static type = 'PageHeaderView';

title: DynamicTextView | null;
image: ContentPreviewImageView | null;
image: ContentPreviewImageView | DecoratedAvatarView | null;
metadata: ContentMetadataView | null;
actions: FlexibleActionsView | null;

constructor(data: RawNode) {
super();
this.title = Parser.parseItem(data.title, DynamicTextView);
this.image = Parser.parseItem(data.image, ContentPreviewImageView);
this.image = Parser.parseItem(data.image, [ ContentPreviewImageView, DecoratedAvatarView ]);
this.metadata = Parser.parseItem(data.metadata, ContentMetadataView);
this.actions = Parser.parseItem(data.actions, FlexibleActionsView);
}
Expand Down
2 changes: 2 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export { default as DataModelSection } from './classes/analytics/DataModelSectio
export { default as StatRow } from './classes/analytics/StatRow.js';
export { default as AudioOnlyPlayability } from './classes/AudioOnlyPlayability.js';
export { default as AutomixPreviewVideo } from './classes/AutomixPreviewVideo.js';
export { default as AvatarView } from './classes/AvatarView.js';
export { default as BackstageImage } from './classes/BackstageImage.js';
export { default as BackstagePost } from './classes/BackstagePost.js';
export { default as BackstagePostThread } from './classes/BackstagePostThread.js';
Expand Down Expand Up @@ -93,6 +94,7 @@ export { default as ContinuationItem } from './classes/ContinuationItem.js';
export { default as ConversationBar } from './classes/ConversationBar.js';
export { default as CopyLink } from './classes/CopyLink.js';
export { default as CreatePlaylistDialog } from './classes/CreatePlaylistDialog.js';
export { default as DecoratedAvatarView } from './classes/DecoratedAvatarView.js';
export { default as DecoratedPlayerBar } from './classes/DecoratedPlayerBar.js';
export { default as DefaultPromoPanel } from './classes/DefaultPromoPanel.js';
export { default as DidYouMean } from './classes/DidYouMean.js';
Expand Down