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 getting about with PageHeader #581

Merged
merged 1 commit into from
Jan 18, 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
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
Loading