From 9a9bb76a928594c5c5f3e828c86081bf79c2562d Mon Sep 17 00:00:00 2001 From: jonz94 Date: Thu, 12 Dec 2024 20:34:07 +0800 Subject: [PATCH] feat: add `VideoMetadataCarouselView` (#839) --- src/parser/classes/CarouselItemView.ts | 16 ++++++++++++++ src/parser/classes/CarouselTitleView.ts | 18 +++++++++++++++ src/parser/classes/TextCarouselItemView.ts | 22 +++++++++++++++++++ .../classes/VideoMetadataCarouselView.ts | 17 ++++++++++++++ src/parser/nodes.ts | 4 ++++ 5 files changed, 77 insertions(+) create mode 100644 src/parser/classes/CarouselItemView.ts create mode 100644 src/parser/classes/CarouselTitleView.ts create mode 100644 src/parser/classes/TextCarouselItemView.ts create mode 100644 src/parser/classes/VideoMetadataCarouselView.ts diff --git a/src/parser/classes/CarouselItemView.ts b/src/parser/classes/CarouselItemView.ts new file mode 100644 index 000000000..61c8adc5f --- /dev/null +++ b/src/parser/classes/CarouselItemView.ts @@ -0,0 +1,16 @@ +import { YTNode } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; +import TextCarouselItemView from './TextCarouselItemView.js'; + +export default class CarouselItemView extends YTNode { + static type = 'CarouselItemView'; + + item_type: string; + carousel_item: TextCarouselItemView | null; + + constructor(data: RawNode) { + super(); + this.item_type = data.itemType; + this.carousel_item = Parser.parseItem(data.carouselItem, TextCarouselItemView); + } +} \ No newline at end of file diff --git a/src/parser/classes/CarouselTitleView.ts b/src/parser/classes/CarouselTitleView.ts new file mode 100644 index 000000000..8024c6481 --- /dev/null +++ b/src/parser/classes/CarouselTitleView.ts @@ -0,0 +1,18 @@ +import { YTNode } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; +import ButtonView from './ButtonView.js'; + +export default class CarouselTitleView extends YTNode { + static type = 'CarouselTitleView'; + + title: string; + previous_button: ButtonView | null; + next_button: ButtonView | null; + + constructor(data: RawNode) { + super(); + this.title = data.title; + this.previous_button = Parser.parseItem(data.previousButton, ButtonView); + this.next_button = Parser.parseItem(data.nextButton, ButtonView); + } +} \ No newline at end of file diff --git a/src/parser/classes/TextCarouselItemView.ts b/src/parser/classes/TextCarouselItemView.ts new file mode 100644 index 000000000..14cfc2bcd --- /dev/null +++ b/src/parser/classes/TextCarouselItemView.ts @@ -0,0 +1,22 @@ +import { YTNode } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; +import { Text } from '../misc.js'; +import ButtonView from './ButtonView.js'; +import NavigationEndpoint from './NavigationEndpoint.js'; + +export default class TextCarouselItemView extends YTNode { + static type = 'TextCarouselItemView'; + + icon_name: string; + text: Text; + on_tap_endpoint: NavigationEndpoint; + button: ButtonView | null; + + constructor(data: RawNode) { + super(); + this.icon_name = data.iconName; + this.text = Text.fromAttributed(data.text); + this.on_tap_endpoint = new NavigationEndpoint(data.onTap); + this.button = Parser.parseItem(data.button, ButtonView); + } +} \ No newline at end of file diff --git a/src/parser/classes/VideoMetadataCarouselView.ts b/src/parser/classes/VideoMetadataCarouselView.ts new file mode 100644 index 000000000..520d5525a --- /dev/null +++ b/src/parser/classes/VideoMetadataCarouselView.ts @@ -0,0 +1,17 @@ +import { YTNode, type ObservedArray } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; +import CarouselItemView from './CarouselItemView.js'; +import CarouselTitleView from './CarouselTitleView.js'; + +export default class VideoMetadataCarouselView extends YTNode { + static type = 'VideoMetadataCarouselView'; + + carousel_titles: ObservedArray | null; + carousel_items: ObservedArray | null; + + constructor(data: RawNode) { + super(); + this.carousel_titles = Parser.parse(data.carouselTitles, true, CarouselTitleView); + this.carousel_items = Parser.parse(data.carouselItems, true, CarouselItemView); + } +} \ No newline at end of file diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index 35f309911..db32fe1eb 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -41,7 +41,9 @@ export { default as Card } from './classes/Card.js'; export { default as CardCollection } from './classes/CardCollection.js'; export { default as CarouselHeader } from './classes/CarouselHeader.js'; export { default as CarouselItem } from './classes/CarouselItem.js'; +export { default as CarouselItemView } from './classes/CarouselItemView.js'; export { default as CarouselLockup } from './classes/CarouselLockup.js'; +export { default as CarouselTitleView } from './classes/CarouselTitleView.js'; export { default as Channel } from './classes/Channel.js'; export { default as ChannelAboutFullMetadata } from './classes/ChannelAboutFullMetadata.js'; export { default as ChannelAgeGate } from './classes/ChannelAgeGate.js'; @@ -441,6 +443,7 @@ export { default as SubscriptionNotificationToggleButton } from './classes/Subsc 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 TextCarouselItemView } from './classes/TextCarouselItemView.js'; export { default as TextFieldView } from './classes/TextFieldView.js'; export { default as TextHeader } from './classes/TextHeader.js'; export { default as ThirdPartyShareTargetSection } from './classes/ThirdPartyShareTargetSection.js'; @@ -494,6 +497,7 @@ export { default as VideoDescriptionInfocardsSection } from './classes/VideoDesc export { default as VideoDescriptionMusicSection } from './classes/VideoDescriptionMusicSection.js'; export { default as VideoDescriptionTranscriptSection } from './classes/VideoDescriptionTranscriptSection.js'; export { default as VideoInfoCardContent } from './classes/VideoInfoCardContent.js'; +export { default as VideoMetadataCarouselView } from './classes/VideoMetadataCarouselView.js'; export { default as VideoOwner } from './classes/VideoOwner.js'; export { default as VideoPrimaryInfo } from './classes/VideoPrimaryInfo.js'; export { default as VideoSecondaryInfo } from './classes/VideoSecondaryInfo.js';