Skip to content

Commit

Permalink
feat(parser): Add ShortsLockupView and BadgeView nodes (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Sep 13, 2024
1 parent bf6cc00 commit e1e76ee
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/mixins/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import PlaylistPanelVideo from '../../parser/classes/PlaylistPanelVideo.js';
import PlaylistVideo from '../../parser/classes/PlaylistVideo.js';
import Post from '../../parser/classes/Post.js';
import ReelItem from '../../parser/classes/ReelItem.js';
import ShortsLockupView from '../../parser/classes/ShortsLockupView.js';
import ReelShelf from '../../parser/classes/ReelShelf.js';
import RichShelf from '../../parser/classes/RichShelf.js';
import Shelf from '../../parser/classes/Shelf.js';
Expand Down Expand Up @@ -78,6 +79,7 @@ export default class Feed<T extends IParsedResponse = IParsedResponse> {
Video,
GridVideo,
ReelItem,
ShortsLockupView,
CompactVideo,
PlaylistVideo,
PlaylistPanelVideo,
Expand Down
16 changes: 16 additions & 0 deletions src/parser/classes/BadgeView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { YTNode } from '../helpers.js';
import type { RawNode } from '../types/RawResponse.js';

export default class BadgeView extends YTNode {
text: string;
style: string;
accessibility_label: string;

constructor(data: RawNode) {
super();

this.text = data.badgeText;
this.style = data.badgeStyle;
this.accessibility_label = data.accessibilityLabel;
}
}
50 changes: 50 additions & 0 deletions src/parser/classes/ShortsLockupView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { YTNode } from '../helpers.js';
import { Parser } from '../index.js';
import type { RawNode } from '../types/RawResponse.js';
import BadgeView from './BadgeView.js';
import Text from './misc/Text.js';
import Thumbnail from './misc/Thumbnail.js';
import NavigationEndpoint from './NavigationEndpoint.js';

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

entity_id: string;
accessibility_text: string;
thumbnail: Thumbnail[];
on_tap_endpoint: NavigationEndpoint;
menu_on_tap: NavigationEndpoint;
index_in_collection: number;
menu_on_tap_a11y_label: string;
overlay_metadata: {
primary_text: Text;
secondary_text?: Text;
};
inline_player_data?: NavigationEndpoint;
badge?: BadgeView | null;

constructor(data: RawNode) {
super();

this.entity_id = data.entityId;
this.accessibility_text = data.accessibilityText;
this.thumbnail = Thumbnail.fromResponse(data.thumbnail);
this.on_tap_endpoint = new NavigationEndpoint(data.onTap);
this.menu_on_tap = new NavigationEndpoint(data.menuOnTap);
this.index_in_collection = data.indexInCollection;
this.menu_on_tap_a11y_label = data.menuOnTapA11yLabel;

this.overlay_metadata = {
primary_text: Text.fromAttributed(data.overlayMetadata.primaryText),
secondary_text: data.overlayMetadata.secondaryText ? Text.fromAttributed(data.overlayMetadata.secondaryText) : undefined
};

if (data.inlinePlayerData?.onVisible) {
this.inline_player_data = new NavigationEndpoint(data.inlinePlayerData.onVisible);
}

if (data.badge) {
this.badge = Parser.parseItem(data.badge, BadgeView);
}
}
}
2 changes: 2 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export { default as AvatarView } from './classes/AvatarView.js';
export { default as BackstageImage } from './classes/BackstageImage.js';
export { default as BackstagePost } from './classes/BackstagePost.js';
export { default as BackstagePostThread } from './classes/BackstagePostThread.js';
export { default as BadgeView } from './classes/BadgeView.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';
Expand Down Expand Up @@ -352,6 +353,7 @@ export { default as SettingsSidebar } from './classes/SettingsSidebar.js';
export { default as SettingsSwitch } from './classes/SettingsSwitch.js';
export { default as SharedPost } from './classes/SharedPost.js';
export { default as Shelf } from './classes/Shelf.js';
export { default as ShortsLockupView } from './classes/ShortsLockupView.js';
export { default as ShowCustomThumbnail } from './classes/ShowCustomThumbnail.js';
export { default as ShowingResultsFor } from './classes/ShowingResultsFor.js';
export { default as SimpleCardContent } from './classes/SimpleCardContent.js';
Expand Down
5 changes: 3 additions & 2 deletions src/parser/youtube/Playlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import PlaylistSidebarPrimaryInfo from '../classes/PlaylistSidebarPrimaryInfo.js
import PlaylistSidebarSecondaryInfo from '../classes/PlaylistSidebarSecondaryInfo.js';
import PlaylistVideoThumbnail from '../classes/PlaylistVideoThumbnail.js';
import ReelItem from '../classes/ReelItem.js';
import ShortsLockupView from '../classes/ShortsLockupView.js';
import VideoOwner from '../classes/VideoOwner.js';
import Alert from '../classes/Alert.js';
import ContinuationItem from '../classes/ContinuationItem.js';
Expand Down Expand Up @@ -67,8 +68,8 @@ export default class Playlist extends Feed<IBrowseResponse> {
return primary_info.stats[index]?.toString() || 'N/A';
}

get items(): ObservedArray<PlaylistVideo | ReelItem> {
return observe(this.videos.as(PlaylistVideo, ReelItem).filter((video) => (video as PlaylistVideo).style !== 'PLAYLIST_VIDEO_RENDERER_STYLE_RECOMMENDED_VIDEO'));
get items(): ObservedArray<PlaylistVideo | ReelItem | ShortsLockupView> {
return observe(this.videos.as(PlaylistVideo, ReelItem, ShortsLockupView).filter((video) => (video as PlaylistVideo).style !== 'PLAYLIST_VIDEO_RENDERER_STYLE_RECOMMENDED_VIDEO'));
}

get has_continuation() {
Expand Down

0 comments on commit e1e76ee

Please sign in to comment.