Skip to content

Commit

Permalink
feat(parser): Add UnifiedSharePanel
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Nov 10, 2024
1 parent fdb7540 commit 4a1397f
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/parser/classes/SharePanelHeader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { type RawNode, Parser } from '../index.js';
import { YTNode } from '../helpers.js';

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

public title: YTNode;

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

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

public title: Text;

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

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

public endpoint?: NavigationEndpoint;
public service_name: string;
public target_id: string;
public title: Text;

constructor(data: RawNode) {
super();
if (Reflect.has(data, 'serviceEndpoint'))
this.endpoint = new NavigationEndpoint(data.serviceEndpoint);
else if (Reflect.has(data, 'navigationEndpoint'))
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);

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

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

public start_at_option_label: Text;

constructor(data: RawNode) {
super();
this.start_at_option_label = new Text(data.startAtOptionLabel);
}
}
14 changes: 14 additions & 0 deletions src/parser/classes/ThirdPartyShareTargetSection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { type RawNode, Parser } from '../index.js';
import { type ObservedArray, YTNode } from '../helpers.js';
import ShareTarget from './ShareTarget.js';

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

public share_targets: ObservedArray<ShareTarget>;

constructor(data: RawNode) {
super();
this.share_targets = Parser.parseArray(data.shareTargets, ShareTarget);
}
}
37 changes: 37 additions & 0 deletions src/parser/classes/UnifiedSharePanel .ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { YTNode } from '../helpers.js';
import { Parser, type RawNode } from '../index.js';

import StartAt from './StartAt.js';
import CopyLink from './CopyLink.js';
import SharePanelHeader from './SharePanelHeader.js';
import ThirdPartyShareTargetSection from './ThirdPartyShareTargetSection.js';

export type ThirdPartyNetworkSection = {
share_target_container: ThirdPartyShareTargetSection | null,
copy_link_container: CopyLink | null,
start_at_container: StartAt | null
};

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

public third_party_network_section?: ThirdPartyNetworkSection;
public header: SharePanelHeader | null;
public share_panel_version: number;

constructor(data: RawNode) {
super();
const contents = data.contents.find((content: RawNode) => content.thirdPartyNetworkSection);

if (!contents) {
this.third_party_network_section = {
share_target_container: Parser.parseItem(contents.thirdPartyNetworkSection.shareTargetContainer, ThirdPartyShareTargetSection),
copy_link_container: Parser.parseItem(contents.thirdPartyNetworkSection.copyLinkContainer, CopyLink),
start_at_container: Parser.parseItem(contents.thirdPartyNetworkSection.startAtContainer, StartAt)
};
}

this.header = Parser.parseItem(data.header, SharePanelHeader);
this.share_panel_version = data.sharePanelVersion;
}
}
6 changes: 6 additions & 0 deletions src/parser/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ export { default as SettingsOptions } from './classes/SettingsOptions.js';
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 SharePanelHeader } from './classes/SharePanelHeader.js';
export { default as SharePanelTitleV15 } from './classes/SharePanelTitleV15.js';
export { default as ShareTarget } from './classes/ShareTarget.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';
Expand All @@ -373,6 +376,7 @@ export { default as SlimOwner } from './classes/SlimOwner.js';
export { default as SlimVideoMetadata } from './classes/SlimVideoMetadata.js';
export { default as SortFilterHeader } from './classes/SortFilterHeader.js';
export { default as SortFilterSubMenu } from './classes/SortFilterSubMenu.js';
export { default as StartAt } from './classes/StartAt.js';
export { default as StructuredDescriptionContent } from './classes/StructuredDescriptionContent.js';
export { default as StructuredDescriptionPlaylistLockup } from './classes/StructuredDescriptionPlaylistLockup.js';
export { default as SubFeedOption } from './classes/SubFeedOption.js';
Expand All @@ -383,6 +387,7 @@ export { default as Tab } from './classes/Tab.js';
export { default as Tabbed } from './classes/Tabbed.js';
export { default as TabbedSearchResults } from './classes/TabbedSearchResults.js';
export { default as TextHeader } from './classes/TextHeader.js';
export { default as ThirdPartyShareTargetSection } from './classes/ThirdPartyShareTargetSection.js';
export { default as ThumbnailBadgeView } from './classes/ThumbnailBadgeView.js';
export { default as ThumbnailHoverOverlayView } from './classes/ThumbnailHoverOverlayView.js';
export { default as ThumbnailLandscapePortrait } from './classes/ThumbnailLandscapePortrait.js';
Expand Down Expand Up @@ -417,6 +422,7 @@ export { default as TranscriptSegmentList } from './classes/TranscriptSegmentLis
export { default as TwoColumnBrowseResults } from './classes/TwoColumnBrowseResults.js';
export { default as TwoColumnSearchResults } from './classes/TwoColumnSearchResults.js';
export { default as TwoColumnWatchNextResults } from './classes/TwoColumnWatchNextResults.js';
export { default as UnifiedSharePanel } from './classes/UnifiedSharePanel .js';

Check failure on line 425 in src/parser/nodes.ts

View workflow job for this annotation

GitHub Actions / lint

Multiple spaces found before '}'
export { default as UniversalWatchCard } from './classes/UniversalWatchCard.js';
export { default as UploadTimeFactoid } from './classes/UploadTimeFactoid.js';
export { default as UpsellDialog } from './classes/UpsellDialog.js';
Expand Down

0 comments on commit 4a1397f

Please sign in to comment.