Skip to content

Commit

Permalink
feat(parser): Add PlaylistThumbnailOverlay
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Dec 10, 2024
1 parent 8e97bbc commit c8173c8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
17 changes: 17 additions & 0 deletions src/parser/classes/PlaylistThumbnailOverlay.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 PlaylistThumbnailOverlay extends YTNode {
static type = 'PlaylistThumbnailOverlay';

public icon_type?: string;
public text: Text;

constructor(data: RawNode) {
super();
if (Reflect.has(data, 'icon'))
this.icon_type = data.icon.iconType;
this.text = new Text(data.text);
}
}
5 changes: 5 additions & 0 deletions src/parser/classes/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class Video extends YTNode {
show_action_menu: boolean;
is_watched: boolean;
menu: Menu | null;
byline_text?: Text;
search_video_result_entity_key?: string;

constructor(data: RawNode) {
Expand Down Expand Up @@ -91,6 +92,10 @@ export default class Video extends YTNode {
if (Reflect.has(data, 'searchVideoResultEntityKey')) {
this.search_video_result_entity_key = data.searchVideoResultEntityKey;
}

if (Reflect.has(data, 'bylineText')) {
this.byline_text = new Text(data.bylineText);
}
}

get description(): string {
Expand Down
12 changes: 8 additions & 4 deletions src/parser/classes/VideoCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import Video from './Video.js';

export default class VideoCard extends Video {
static type = 'VideoCard';

public metadata_text?: Text;
public byline_text?: Text;

constructor(data: RawNode) {
super(data);
if (Reflect.has(data, 'metadataText')) {
const metadata = new Text(data.metadataText);
if (metadata.text) {
this.short_view_count = new Text({ simpleText: metadata.text.split('·')[0].trim() } as RawNode);
this.published = new Text({ simpleText: metadata.text.split('·')[1].trim() } as RawNode);
this.metadata_text = new Text(data.metadataText);
if (this.metadata_text.text) {
this.short_view_count = new Text({ simpleText: this.metadata_text.text.split('·')[0]?.trim() } as RawNode);
this.published = new Text({ simpleText: this.metadata_text.text.split('·')[1]?.trim() } as RawNode);
}
}

if (Reflect.has(data, 'bylineText')) {
this.author = new Author(data.bylineText, data.ownerBadges, data.channelThumbnailSupportedRenderers?.channelThumbnailWithLinkRenderer?.thumbnail);
}
Expand Down
5 changes: 3 additions & 2 deletions src/parser/classes/menus/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import SegmentedLikeDislikeButtonView from '../SegmentedLikeDislikeButtonView.js
import MenuFlexibleItem from './MenuFlexibleItem.js';
import LikeButton from '../LikeButton.js';
import ToggleButton from '../ToggleButton.js';
import FlexibleActionsView from '../FlexibleActionsView.js';

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

public items: ObservedArray<YTNode>;
public flexible_items: ObservedArray<MenuFlexibleItem>;
public top_level_buttons: ObservedArray<ToggleButton | LikeButton | Button |ButtonView | SegmentedLikeDislikeButtonView>;
public top_level_buttons: ObservedArray<ToggleButton | LikeButton | Button |ButtonView | SegmentedLikeDislikeButtonView | FlexibleActionsView>;
public label?: string;

constructor(data: RawNode) {
super();
this.items = Parser.parseArray(data.items);
this.flexible_items = Parser.parseArray(data.flexibleItems, MenuFlexibleItem);
this.top_level_buttons = Parser.parseArray(data.topLevelButtons, [ ToggleButton, LikeButton, Button, ButtonView, SegmentedLikeDislikeButtonView ]);
this.top_level_buttons = Parser.parseArray(data.topLevelButtons, [ ToggleButton, LikeButton, Button, ButtonView, SegmentedLikeDislikeButtonView, FlexibleActionsView ]);

if (Reflect.has(data, 'accessibility') && Reflect.has(data.accessibility, 'accessibilityData')) {
this.label = data.accessibility.accessibilityData.label;
Expand Down
1 change: 1 addition & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export { default as PlaylistPanelVideoWrapper } from './classes/PlaylistPanelVid
export { default as PlaylistSidebar } from './classes/PlaylistSidebar.js';
export { default as PlaylistSidebarPrimaryInfo } from './classes/PlaylistSidebarPrimaryInfo.js';
export { default as PlaylistSidebarSecondaryInfo } from './classes/PlaylistSidebarSecondaryInfo.js';
export { default as PlaylistThumbnailOverlay } from './classes/PlaylistThumbnailOverlay.js';
export { default as PlaylistVideo } from './classes/PlaylistVideo.js';
export { default as PlaylistVideoList } from './classes/PlaylistVideoList.js';
export { default as PlaylistVideoThumbnail } from './classes/PlaylistVideoThumbnail.js';
Expand Down

0 comments on commit c8173c8

Please sign in to comment.