Skip to content

Commit

Permalink
feat(Channel): Support getting about with PageHeader (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 18, 2024
1 parent fed3512 commit 2e710dc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
28 changes: 27 additions & 1 deletion src/parser/classes/DescriptionPreviewView.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { Parser, type RawNode } from '../index.js';
import EngagementPanelSectionList from './EngagementPanelSectionList.js';
import Text from './misc/Text.js';

export default class DescriptionPreviewView extends YTNode {
Expand All @@ -9,6 +10,16 @@ export default class DescriptionPreviewView extends YTNode {
max_lines: number;
truncation_text: Text;
always_show_truncation_text: boolean;
more_endpoint?: {
show_engagement_panel_endpoint: {
engagement_panel: EngagementPanelSectionList | null,
engagement_panel_popup_type: string;
identifier: {
surface: string,
tag: string
}
}
};

constructor(data: RawNode) {
super();
Expand All @@ -17,5 +28,20 @@ export default class DescriptionPreviewView extends YTNode {
this.max_lines = parseInt(data.maxLines);
this.truncation_text = Text.fromAttributed(data.truncationText);
this.always_show_truncation_text = !!data.alwaysShowTruncationText;

if (data.rendererContext.commandContext?.onTap?.innertubeCommand?.showEngagementPanelEndpoint) {
const endpoint = data.rendererContext.commandContext?.onTap?.innertubeCommand?.showEngagementPanelEndpoint;

this.more_endpoint = {
show_engagement_panel_endpoint: {
engagement_panel: Parser.parseItem(endpoint.engagementPanel, EngagementPanelSectionList),
engagement_panel_popup_type: endpoint.engagementPanelPresentationConfigs.engagementPanelPopupPresentationConfig.popupType,
identifier: {
surface: endpoint.identifier.surface,
tag: endpoint.identifier.tag
}
}
};
}
}
}
13 changes: 9 additions & 4 deletions src/parser/youtube/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ export default class Channel extends TabbedFeed<IBrowseResponse> {
if (this.hasTabWithURL('about')) {
const tab = await this.getTabByURL('about');
return tab.memo.getType(ChannelAboutFullMetadata)[0];
} else if (this.header?.is(C4TabbedHeader) && this.header.tagline) {
}

const tagline = this.header?.is(C4TabbedHeader) && this.header.tagline;

if (this.header.tagline.more_endpoint instanceof NavigationEndpoint) {
const response = await this.header.tagline.more_endpoint.call(this.actions);
if (tagline || this.header?.is(PageHeader) && this.header.content?.description) {
if (tagline && tagline.more_endpoint instanceof NavigationEndpoint) {
const response = await tagline.more_endpoint.call(this.actions);

const tab = new TabbedFeed<IBrowseResponse>(this.actions, response, false);
return tab.memo.getType(ChannelAboutFullMetadata)[0];
Expand Down Expand Up @@ -271,7 +274,9 @@ export default class Channel extends TabbedFeed<IBrowseResponse> {

get has_about(): boolean {
// Game topic channels still have an about tab, user channels have switched to the popup
return this.hasTabWithURL('about') || !!(this.header?.is(C4TabbedHeader) && this.header.tagline?.more_endpoint);
return this.hasTabWithURL('about') ||
!!(this.header?.is(C4TabbedHeader) && this.header.tagline?.more_endpoint) ||
!!(this.header?.is(PageHeader) && this.header.content?.description?.more_endpoint);
}

get has_search(): boolean {
Expand Down

0 comments on commit 2e710dc

Please sign in to comment.