Skip to content

Commit

Permalink
fix(Library)!: Add support for the new layout and remove profile & st…
Browse files Browse the repository at this point in the history
…ats info
  • Loading branch information
LuanRT committed Dec 1, 2023
1 parent f74ed5a commit 4261915
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 14 deletions.
28 changes: 28 additions & 0 deletions src/parser/classes/ButtonView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import NavigationEndpoint from './NavigationEndpoint.js';

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

icon_name: string;
title: string;
accessibility_text: string;
style: string;
is_full_width: boolean;
type: string;
button_size: string;
on_tap: NavigationEndpoint;

constructor(data: RawNode) {
super();
this.icon_name = data.iconName;
this.title = data.title;
this.accessibility_text = data.accessibilityText;
this.style = data.style;
this.is_full_width = data.isFullWidth;
this.type = data.type;
this.button_size = data.buttonSize;
this.on_tap = new NavigationEndpoint(data.onTap);
}
}
26 changes: 26 additions & 0 deletions src/parser/classes/ContentMetadataView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../index.js';
import { Text } from '../misc.js';

export type MetadataRow = {
metadata_parts: {
text: Text;
}[];
};

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

metadata_rows: MetadataRow[];
delimiter: string;

constructor(data: RawNode) {
super();
this.metadata_rows = data.metadataRows.map((row: RawNode) => ({
metadata_parts: row.metadataParts.map((part: RawNode) => ({
text: Text.fromAttributed(part.text)
}))
}));
this.delimiter = data.delimiter;
}
}
22 changes: 22 additions & 0 deletions src/parser/classes/FlexibleActionsView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { type ObservedArray, YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import ButtonView from './ButtonView.js';

export type ActionRow = {
actions: ObservedArray<ButtonView>;
};

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

actions_rows: ActionRow[];
style: string;

constructor(data: RawNode) {
super();
this.actions_rows = data.actionsRows.map((row: RawNode) => ({
actions: Parser.parseArray(row.actions, ButtonView)
}));
this.style = data.style;
}
}
10 changes: 8 additions & 2 deletions src/parser/classes/PageHeaderView.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import ContentMetadataView from './ContentMetadataView.js';
import ContentPreviewImageView from './ContentPreviewImageView.js';
import DynamicTextView from './DynamicTextView.js';
import FlexibleActionsView from './FlexibleActionsView.js';

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

image: ContentPreviewImageView | null;
title: DynamicTextView | null;
image: ContentPreviewImageView | null;
metadata: YTNode | null;
actions: YTNode | null;

constructor(data: RawNode) {
super();
this.image = Parser.parseItem(data.image, ContentPreviewImageView);
this.title = Parser.parseItem(data.title, DynamicTextView);
this.image = Parser.parseItem(data.image, ContentPreviewImageView);
this.metadata = Parser.parseItem(data.metadata, ContentMetadataView);
this.actions = Parser.parseItem(data.actions, FlexibleActionsView);
}
}
3 changes: 3 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export { default as BackstagePostThread } from './classes/BackstagePostThread.js
export { default as BrowseFeedActions } from './classes/BrowseFeedActions.js';
export { default as BrowserMediaSession } from './classes/BrowserMediaSession.js';
export { default as Button } from './classes/Button.js';
export { default as ButtonView } from './classes/ButtonView.js';
export { default as C4TabbedHeader } from './classes/C4TabbedHeader.js';
export { default as CallToActionButton } from './classes/CallToActionButton.js';
export { default as Card } from './classes/Card.js';
Expand Down Expand Up @@ -86,6 +87,7 @@ export { default as CompactPlaylist } from './classes/CompactPlaylist.js';
export { default as CompactStation } from './classes/CompactStation.js';
export { default as CompactVideo } from './classes/CompactVideo.js';
export { default as ConfirmDialog } from './classes/ConfirmDialog.js';
export { default as ContentMetadataView } from './classes/ContentMetadataView.js';
export { default as ContentPreviewImageView } from './classes/ContentPreviewImageView.js';
export { default as ContinuationItem } from './classes/ContinuationItem.js';
export { default as ConversationBar } from './classes/ConversationBar.js';
Expand Down Expand Up @@ -118,6 +120,7 @@ export { default as FancyDismissibleDialog } from './classes/FancyDismissibleDia
export { default as FeedFilterChipBar } from './classes/FeedFilterChipBar.js';
export { default as FeedNudge } from './classes/FeedNudge.js';
export { default as FeedTabbedHeader } from './classes/FeedTabbedHeader.js';
export { default as FlexibleActionsView } from './classes/FlexibleActionsView.js';
export { default as GameCard } from './classes/GameCard.js';
export { default as GameDetails } from './classes/GameDetails.js';
export { default as Grid } from './classes/Grid.js';
Expand Down
15 changes: 3 additions & 12 deletions src/parser/youtube/Library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,12 @@ import Menu from '../classes/menus/Menu.js';
import Shelf from '../classes/Shelf.js';
import Button from '../classes/Button.js';

import ProfileColumnStats from '../classes/ProfileColumnStats.js';
import ProfileColumnUserInfo from '../classes/ProfileColumnUserInfo.js';

import type { IBrowseResponse } from '../types/ParsedResponse.js';
import type { ApiResponse } from '../../core/Actions.js';
import { PageHeader } from '../nodes.js';

class Library extends Feed<IBrowseResponse> {
profile: {
stats?: ProfileColumnStats;
user_info?: ProfileColumnUserInfo;
};

header: PageHeader | null;
sections;

constructor(actions: Actions, data: ApiResponse | IBrowseResponse) {
Expand All @@ -28,10 +22,7 @@ class Library extends Feed<IBrowseResponse> {
if (!this.page.contents_memo)
throw new InnertubeError('Page contents not found');

const stats = this.page.contents_memo.getType(ProfileColumnStats).first();
const user_info = this.page.contents_memo.getType(ProfileColumnUserInfo).first();

this.profile = { stats, user_info };
this.header = this.memo.getType(PageHeader).first();

const shelves = this.page.contents_memo.getType(Shelf);

Expand Down

0 comments on commit 4261915

Please sign in to comment.