From 8b6958778721ba274283f641779fb60bc6f42cd2 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Sun, 27 Aug 2023 21:29:23 +0200 Subject: [PATCH] feat(parser): Add `AlertWithButton` (#486) --- src/parser/classes/AlertWithButton.ts | 19 +++++++++++++++++++ src/parser/nodes.ts | 1 + src/parser/parser.ts | 3 ++- src/parser/types/ParsedResponse.ts | 5 +++-- 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/parser/classes/AlertWithButton.ts diff --git a/src/parser/classes/AlertWithButton.ts b/src/parser/classes/AlertWithButton.ts new file mode 100644 index 000000000..677f97e8b --- /dev/null +++ b/src/parser/classes/AlertWithButton.ts @@ -0,0 +1,19 @@ +import Button from './Button.js'; +import Text from './misc/Text.js'; +import { YTNode } from '../helpers.js'; +import { Parser, type RawNode } from '../index.js'; + +export default class AlertWithButton extends YTNode { + static type = 'AlertWithButton'; + + text: Text; + alert_type: string; + dismiss_button: Button | null; + + constructor(data: RawNode) { + super(); + this.text = new Text(data.text); + this.alert_type = data.type; + this.dismiss_button = Parser.parseItem(data.dismissButton, Button); + } +} \ No newline at end of file diff --git a/src/parser/nodes.ts b/src/parser/nodes.ts index 750b92290..a99185fd2 100644 --- a/src/parser/nodes.ts +++ b/src/parser/nodes.ts @@ -8,6 +8,7 @@ export { default as AccountSectionList } from './classes/AccountSectionList.js'; export { default as AppendContinuationItemsAction } from './classes/actions/AppendContinuationItemsAction.js'; export { default as OpenPopupAction } from './classes/actions/OpenPopupAction.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'; export { default as AnalyticsRoot } from './classes/analytics/AnalyticsRoot.js'; export { default as AnalyticsShortsCarouselCard } from './classes/analytics/AnalyticsShortsCarouselCard.js'; diff --git a/src/parser/parser.ts b/src/parser/parser.ts index b1d039469..31612bf45 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -6,6 +6,7 @@ import PlayerCaptionsTracklist from './classes/PlayerCaptionsTracklist.js'; import PlayerLiveStoryboardSpec from './classes/PlayerLiveStoryboardSpec.js'; import PlayerStoryboardSpec from './classes/PlayerStoryboardSpec.js'; import Alert from './classes/Alert.js'; +import AlertWithButton from './classes/AlertWithButton.js'; import type { IParsedResponse, IRawResponse, RawData, RawNode } from './types/index.js'; @@ -310,7 +311,7 @@ export function parseResponse(data: parsed_data.overlay = overlay; } - const alerts = parseArray(data.alerts, Alert); + const alerts = parseArray(data.alerts, [ Alert, AlertWithButton ]); if (alerts.length) { parsed_data.alerts = alerts; } diff --git a/src/parser/types/ParsedResponse.ts b/src/parser/types/ParsedResponse.ts index 29933ce77..bbc273f53 100644 --- a/src/parser/types/ParsedResponse.ts +++ b/src/parser/types/ParsedResponse.ts @@ -15,6 +15,7 @@ import type PlayerLiveStoryboardSpec from '../classes/PlayerLiveStoryboardSpec.j import type PlayerStoryboardSpec from '../classes/PlayerStoryboardSpec.js'; import type VideoDetails from '../classes/misc/VideoDetails.js'; import type Alert from '../classes/Alert.js'; +import type AlertWithButton from '../classes/AlertWithButton.js'; import type NavigationEndpoint from '../classes/NavigationEndpoint.js'; import type PlayerAnnotationsExpanded from '../classes/PlayerAnnotationsExpanded.js'; import type EngagementPanelSectionList from '../classes/EngagementPanelSectionList.js'; @@ -44,7 +45,7 @@ export interface IParsedResponse { metadata?: SuperParsedResult; microformat?: YTNode; overlay?: YTNode; - alerts?: ObservedArray; + alerts?: ObservedArray; refinements?: string[]; estimated_results?: number; player_overlays?: SuperParsedResult; @@ -122,7 +123,7 @@ export interface IBrowseResponse { header_memo?: Memo; metadata?: SuperParsedResult; microformat?: YTNode; - alerts?: ObservedArray; + alerts?: ObservedArray; sidebar?: YTNode; sidebar_memo?: Memo; }