Skip to content

Commit

Permalink
fear(parser): Add DecoratedAvatarView (LuanRT#544)
Browse files Browse the repository at this point in the history
* Add DecoratedAvatarView

* Export the class

* Update PageHeaderView

* Adjust thumbnails

* Add avatar view

* Apply suggestions from code review

---------

Co-authored-by: absidue <48293849+absidue@users.noreply.github.com>
  • Loading branch information
iBicha and absidue authored Dec 27, 2023
1 parent e7efec2 commit 9618f38
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
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;
}
}
19 changes: 19 additions & 0 deletions src/parser/classes/DecoratedAvatarView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import AvatarView from './AvatarView.js';

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

avatar: AvatarView;
a11y_label: string;
on_tap_endpoint: NavigationEndpoint;

constructor(data: RawNode) {
super();
this.avatar = new AvatarView(data.avatar.avatarViewModel);
this.a11y_label = data.a11yLabel;
this.on_tap_endpoint = 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

0 comments on commit 9618f38

Please sign in to comment.