Skip to content

Commit 4a1397f

Browse files
committed
feat(parser): Add UnifiedSharePanel
1 parent fdb7540 commit 4a1397f

7 files changed

+123
-0
lines changed
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { type RawNode, Parser } from '../index.js';
2+
import { YTNode } from '../helpers.js';
3+
4+
export default class SharePanelHeader extends YTNode {
5+
static type = 'SharePanelHeader';
6+
7+
public title: YTNode;
8+
9+
constructor(data: RawNode) {
10+
super();
11+
this.title = Parser.parseItem(data.title);
12+
}
13+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RawNode } from '../index.js';
2+
import { YTNode } from '../helpers.js';
3+
import { Text } from '../misc.js';
4+
5+
export default class SharePanelTitleV15 extends YTNode {
6+
static type = 'SharePanelTitleV15';
7+
8+
public title: Text;
9+
10+
constructor(data: RawNode) {
11+
super();
12+
this.title = new Text(data.title);
13+
}
14+
}

src/parser/classes/ShareTarget.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { RawNode } from '../index.js';
2+
import { Text } from '../misc.js';
3+
import { YTNode } from '../helpers.js';
4+
import NavigationEndpoint from './NavigationEndpoint.js';
5+
6+
export default class ShareTarget extends YTNode {
7+
static type = 'ShareTarget';
8+
9+
public endpoint?: NavigationEndpoint;
10+
public service_name: string;
11+
public target_id: string;
12+
public title: Text;
13+
14+
constructor(data: RawNode) {
15+
super();
16+
if (Reflect.has(data, 'serviceEndpoint'))
17+
this.endpoint = new NavigationEndpoint(data.serviceEndpoint);
18+
else if (Reflect.has(data, 'navigationEndpoint'))
19+
this.endpoint = new NavigationEndpoint(data.navigationEndpoint);
20+
21+
this.service_name = data.serviceName;
22+
this.target_id = data.targetId;
23+
this.title = new Text(data.title);
24+
}
25+
}

src/parser/classes/StartAt.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { RawNode } from '../index.js';
2+
import { YTNode } from '../helpers.js';
3+
import { Text } from '../misc.js';
4+
5+
export default class StartAt extends YTNode {
6+
static type = 'StartAt';
7+
8+
public start_at_option_label: Text;
9+
10+
constructor(data: RawNode) {
11+
super();
12+
this.start_at_option_label = new Text(data.startAtOptionLabel);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { type RawNode, Parser } from '../index.js';
2+
import { type ObservedArray, YTNode } from '../helpers.js';
3+
import ShareTarget from './ShareTarget.js';
4+
5+
export default class ThirdPartyShareTargetSection extends YTNode {
6+
static type = 'ThirdPartyShareTargetSection';
7+
8+
public share_targets: ObservedArray<ShareTarget>;
9+
10+
constructor(data: RawNode) {
11+
super();
12+
this.share_targets = Parser.parseArray(data.shareTargets, ShareTarget);
13+
}
14+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { YTNode } from '../helpers.js';
2+
import { Parser, type RawNode } from '../index.js';
3+
4+
import StartAt from './StartAt.js';
5+
import CopyLink from './CopyLink.js';
6+
import SharePanelHeader from './SharePanelHeader.js';
7+
import ThirdPartyShareTargetSection from './ThirdPartyShareTargetSection.js';
8+
9+
export type ThirdPartyNetworkSection = {
10+
share_target_container: ThirdPartyShareTargetSection | null,
11+
copy_link_container: CopyLink | null,
12+
start_at_container: StartAt | null
13+
};
14+
15+
export default class UnifiedSharePanel extends YTNode {
16+
static type = 'UnifiedSharePanel';
17+
18+
public third_party_network_section?: ThirdPartyNetworkSection;
19+
public header: SharePanelHeader | null;
20+
public share_panel_version: number;
21+
22+
constructor(data: RawNode) {
23+
super();
24+
const contents = data.contents.find((content: RawNode) => content.thirdPartyNetworkSection);
25+
26+
if (!contents) {
27+
this.third_party_network_section = {
28+
share_target_container: Parser.parseItem(contents.thirdPartyNetworkSection.shareTargetContainer, ThirdPartyShareTargetSection),
29+
copy_link_container: Parser.parseItem(contents.thirdPartyNetworkSection.copyLinkContainer, CopyLink),
30+
start_at_container: Parser.parseItem(contents.thirdPartyNetworkSection.startAtContainer, StartAt)
31+
};
32+
}
33+
34+
this.header = Parser.parseItem(data.header, SharePanelHeader);
35+
this.share_panel_version = data.sharePanelVersion;
36+
}
37+
}

src/parser/nodes.ts

+6
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ export { default as SettingsOptions } from './classes/SettingsOptions.js';
358358
export { default as SettingsSidebar } from './classes/SettingsSidebar.js';
359359
export { default as SettingsSwitch } from './classes/SettingsSwitch.js';
360360
export { default as SharedPost } from './classes/SharedPost.js';
361+
export { default as SharePanelHeader } from './classes/SharePanelHeader.js';
362+
export { default as SharePanelTitleV15 } from './classes/SharePanelTitleV15.js';
363+
export { default as ShareTarget } from './classes/ShareTarget.js';
361364
export { default as Shelf } from './classes/Shelf.js';
362365
export { default as ShortsLockupView } from './classes/ShortsLockupView.js';
363366
export { default as ShowCustomThumbnail } from './classes/ShowCustomThumbnail.js';
@@ -373,6 +376,7 @@ export { default as SlimOwner } from './classes/SlimOwner.js';
373376
export { default as SlimVideoMetadata } from './classes/SlimVideoMetadata.js';
374377
export { default as SortFilterHeader } from './classes/SortFilterHeader.js';
375378
export { default as SortFilterSubMenu } from './classes/SortFilterSubMenu.js';
379+
export { default as StartAt } from './classes/StartAt.js';
376380
export { default as StructuredDescriptionContent } from './classes/StructuredDescriptionContent.js';
377381
export { default as StructuredDescriptionPlaylistLockup } from './classes/StructuredDescriptionPlaylistLockup.js';
378382
export { default as SubFeedOption } from './classes/SubFeedOption.js';
@@ -383,6 +387,7 @@ export { default as Tab } from './classes/Tab.js';
383387
export { default as Tabbed } from './classes/Tabbed.js';
384388
export { default as TabbedSearchResults } from './classes/TabbedSearchResults.js';
385389
export { default as TextHeader } from './classes/TextHeader.js';
390+
export { default as ThirdPartyShareTargetSection } from './classes/ThirdPartyShareTargetSection.js';
386391
export { default as ThumbnailBadgeView } from './classes/ThumbnailBadgeView.js';
387392
export { default as ThumbnailHoverOverlayView } from './classes/ThumbnailHoverOverlayView.js';
388393
export { default as ThumbnailLandscapePortrait } from './classes/ThumbnailLandscapePortrait.js';
@@ -417,6 +422,7 @@ export { default as TranscriptSegmentList } from './classes/TranscriptSegmentLis
417422
export { default as TwoColumnBrowseResults } from './classes/TwoColumnBrowseResults.js';
418423
export { default as TwoColumnSearchResults } from './classes/TwoColumnSearchResults.js';
419424
export { default as TwoColumnWatchNextResults } from './classes/TwoColumnWatchNextResults.js';
425+
export { default as UnifiedSharePanel } from './classes/UnifiedSharePanel .js';
420426
export { default as UniversalWatchCard } from './classes/UniversalWatchCard.js';
421427
export { default as UploadTimeFactoid } from './classes/UploadTimeFactoid.js';
422428
export { default as UpsellDialog } from './classes/UpsellDialog.js';

0 commit comments

Comments
 (0)