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(Channel): Support PageHeader being used on user channels #577

Merged
merged 1 commit into from
Jan 13, 2024
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
17 changes: 17 additions & 0 deletions src/parser/classes/AttributionView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import Text from './misc/Text.js';

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

text: Text;
suffix: Text;

constructor(data: RawNode) {
super();

this.text = Text.fromAttributed(data.text);
this.suffix = Text.fromAttributed(data.suffix);
}
}
21 changes: 21 additions & 0 deletions src/parser/classes/DescriptionPreviewView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import Text from './misc/Text.js';

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

description: Text;
max_lines: number;
truncation_text: Text;
always_show_truncation_text: boolean;

constructor(data: RawNode) {
super();

this.description = Text.fromAttributed(data.description);
this.max_lines = parseInt(data.maxLines);
this.truncation_text = Text.fromAttributed(data.truncationText);
this.always_show_truncation_text = !!data.alwaysShowTruncationText;
}
}
7 changes: 5 additions & 2 deletions src/parser/classes/DynamicTextView.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import Text from './misc/Text.js';

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

text: string;
text: Text;
max_lines: number;

constructor(data: RawNode) {
super();
this.text = data.text.content;
this.text = Text.fromAttributed(data.text);
this.max_lines = parseInt(data.maxLines);
}
}
19 changes: 19 additions & 0 deletions src/parser/classes/ModalWithTitleAndButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import Button from './Button.js';
import Text from './misc/Text.js';

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

title: Text;
content: Text;
button: Button | null;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);
this.content = new Text(data.content);
this.button = Parser.parseItem(data.button, Button);
}
}
11 changes: 11 additions & 0 deletions src/parser/classes/NavigationEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import type { IParsedResponse } from '../types/ParsedResponse.js';
import CreatePlaylistDialog from './CreatePlaylistDialog.js';
import type ModalWithTitleAndButton from './ModalWithTitleAndButton.js';
import OpenPopupAction from './actions/OpenPopupAction.js';

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

payload;
dialog?: CreatePlaylistDialog | YTNode | null;
modal?: ModalWithTitleAndButton | YTNode | null;
open_popup?: OpenPopupAction | null;

next_endpoint?: NavigationEndpoint;

metadata: {
url?: string;
api_url?: string;
Expand Down Expand Up @@ -41,6 +45,13 @@ export default class NavigationEndpoint extends YTNode {
this.dialog = Parser.parseItem(this.payload.dialog || this.payload.content);
}

if (Reflect.has(this.payload, 'modal')) {
this.modal = Parser.parseItem(this.payload.modal);
}

if (Reflect.has(this.payload, 'nextEndpoint')) {
this.next_endpoint = new NavigationEndpoint(this.payload.nextEndpoint);
}

if (data?.serviceEndpoint) {
data = data.serviceEndpoint;
Expand Down
6 changes: 6 additions & 0 deletions src/parser/classes/PageHeaderView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import ContentPreviewImageView from './ContentPreviewImageView.js';
import DecoratedAvatarView from './DecoratedAvatarView.js';
import DynamicTextView from './DynamicTextView.js';
import FlexibleActionsView from './FlexibleActionsView.js';
import DescriptionPreviewView from './DescriptionPreviewView.js';
import AttributionView from './AttributionView.js';

export default class PageHeaderView extends YTNode {
static type = 'PageHeaderView';
Expand All @@ -13,12 +15,16 @@ export default class PageHeaderView extends YTNode {
image: ContentPreviewImageView | DecoratedAvatarView | null;
metadata: ContentMetadataView | null;
actions: FlexibleActionsView | null;
description: DescriptionPreviewView | null;
attributation: AttributionView | null;

constructor(data: RawNode) {
super();
this.title = Parser.parseItem(data.title, DynamicTextView);
this.image = Parser.parseItem(data.image, [ ContentPreviewImageView, DecoratedAvatarView ]);
this.metadata = Parser.parseItem(data.metadata, ContentMetadataView);
this.actions = Parser.parseItem(data.actions, FlexibleActionsView);
this.description = Parser.parseItem(data.description, DescriptionPreviewView);
this.attributation = Parser.parseItem(data.attributation, AttributionView);
}
}
3 changes: 3 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { default as AnalyticsVodCarouselCard } from './classes/analytics/Analyti
export { default as CtaGoToCreatorStudio } from './classes/analytics/CtaGoToCreatorStudio.js';
export { default as DataModelSection } from './classes/analytics/DataModelSection.js';
export { default as StatRow } from './classes/analytics/StatRow.js';
export { default as AttributionView } from './classes/AttributionView.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';
Expand Down Expand Up @@ -97,6 +98,7 @@ export { default as CreatePlaylistDialog } from './classes/CreatePlaylistDialog.
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 DescriptionPreviewView } from './classes/DescriptionPreviewView.js';
export { default as DidYouMean } from './classes/DidYouMean.js';
export { default as DislikeButtonView } from './classes/DislikeButtonView.js';
export { default as DownloadButton } from './classes/DownloadButton.js';
Expand Down Expand Up @@ -231,6 +233,7 @@ export { default as MetadataRowHeader } from './classes/MetadataRowHeader.js';
export { default as MetadataScreen } from './classes/MetadataScreen.js';
export { default as MicroformatData } from './classes/MicroformatData.js';
export { default as Mix } from './classes/Mix.js';
export { default as ModalWithTitleAndButton } from './classes/ModalWithTitleAndButton.js';
export { default as Movie } from './classes/Movie.js';
export { default as MovingThumbnail } from './classes/MovingThumbnail.js';
export { default as MultiMarkersPlayerBar } from './classes/MultiMarkersPlayerBar.js';
Expand Down
Loading