Skip to content

Commit

Permalink
feat(parser): Add AddToPlaylist node
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 17, 2024
1 parent c68810d commit 2940f7b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/parser/classes/AddToPlaylist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { type ObservedArray, YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';
import Button from './Button.js';
import MenuTitle from './MenuTitle.js';
import PlaylistAddToOption from './PlaylistAddToOption.js';

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

public actions: ObservedArray<MenuTitle | Button>;
public playlists: ObservedArray<PlaylistAddToOption>;

constructor(data: RawNode) {
super();
this.actions = Parser.parseArray(data.actions, [ MenuTitle, Button ]);
this.playlists = Parser.parseArray(data.playlists, PlaylistAddToOption);
}
}
14 changes: 14 additions & 0 deletions src/parser/classes/MenuTitle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { YTNode } from '../helpers.js';
import { Text } from '../misc.js';
import type { RawNode } from '../index.js';

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

public title: Text;

constructor(data: RawNode) {
super();
this.title = new Text(data.title);
}
}
31 changes: 31 additions & 0 deletions src/parser/classes/PlaylistAddToOption.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { YTNode } from '../helpers.js';
import { Text } from '../misc.js';
import NavigationEndpoint from './NavigationEndpoint.js';
import type { RawNode } from '../index.js';

export type PrivacyIcon = {
icon_type: string | null;
};

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

public add_to_playlist_service_endpoint: NavigationEndpoint;
public contains_selected_videos: boolean;
public playlist_id: string;
public privacy: string;
public privacy_icon: PrivacyIcon;
public remove_from_playlist_service_endpoint: NavigationEndpoint;
public title: Text;

constructor(data: RawNode) {
super();
this.add_to_playlist_service_endpoint = new NavigationEndpoint(data.addToPlaylistServiceEndpoint);
this.contains_selected_videos = data.containsSelectedVideos;
this.playlist_id = data.playlistId;
this.privacy = data.privacy;
this.privacy_icon = { icon_type: data.privacyIcon?.iconType || null };
this.remove_from_playlist_service_endpoint = new NavigationEndpoint(data.removeFromPlaylistServiceEndpoint);
this.title = new Text(data.title);
}
}
3 changes: 3 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { default as OpenPopupAction } from './classes/actions/OpenPopupAction.js
export { default as SignalAction } from './classes/actions/SignalAction.js';
export { default as UpdateEngagementPanelAction } from './classes/actions/UpdateEngagementPanelAction.js';
export { default as UpdateSubscribeButtonAction } from './classes/actions/UpdateSubscribeButtonAction.js';
export { default as AddToPlaylist } from './classes/AddToPlaylist.js';
export { default as Alert } from './classes/Alert.js';
export { default as AlertWithButton } from './classes/AlertWithButton.js';
export { default as AnalyticsMainAppKeyMetrics } from './classes/analytics/AnalyticsMainAppKeyMetrics.js';
Expand Down Expand Up @@ -240,6 +241,7 @@ export { default as MusicMenuItemDivider } from './classes/menus/MusicMenuItemDi
export { default as MusicMultiSelectMenu } from './classes/menus/MusicMultiSelectMenu.js';
export { default as MusicMultiSelectMenuItem } from './classes/menus/MusicMultiSelectMenuItem.js';
export { default as SimpleMenuHeader } from './classes/menus/SimpleMenuHeader.js';
export { default as MenuTitle } from './classes/MenuTitle.js';
export { default as MerchandiseItem } from './classes/MerchandiseItem.js';
export { default as MerchandiseShelf } from './classes/MerchandiseShelf.js';
export { default as Message } from './classes/Message.js';
Expand Down Expand Up @@ -307,6 +309,7 @@ export { default as PlayerOverlayAutoplay } from './classes/PlayerOverlayAutopla
export { default as PlayerOverlayVideoDetails } from './classes/PlayerOverlayVideoDetails.js';
export { default as PlayerStoryboardSpec } from './classes/PlayerStoryboardSpec.js';
export { default as Playlist } from './classes/Playlist.js';
export { default as PlaylistAddToOption } from './classes/PlaylistAddToOption.js';
export { default as PlaylistCustomThumbnail } from './classes/PlaylistCustomThumbnail.js';
export { default as PlaylistHeader } from './classes/PlaylistHeader.js';
export { default as PlaylistInfoCardContent } from './classes/PlaylistInfoCardContent.js';
Expand Down

0 comments on commit 2940f7b

Please sign in to comment.