Skip to content

Commit

Permalink
feat(parser): Parse OpenPopupAction in `onResponseReceivedEndpoints…
Browse files Browse the repository at this point in the history
…` arrays
  • Loading branch information
LuanRT committed Dec 18, 2024
1 parent e571ee2 commit 45b7342
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
16 changes: 10 additions & 6 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import VideoDetails from './classes/misc/VideoDetails.js';
import NavigationEndpoint from './classes/NavigationEndpoint.js';
import CommentView from './classes/comments/CommentView.js';
import MusicThumbnail from './classes/MusicThumbnail.js';
import OpenPopupAction from './classes/actions/OpenPopupAction.js';
import AppendContinuationItemsAction from './classes/actions/AppendContinuationItemsAction.js';
import type { IParsedResponse, IRawResponse, RawData, RawNode } from './types/index.js';

const TAG = 'Parser';
Expand Down Expand Up @@ -385,7 +387,7 @@ export function parseResponse<T extends IParsedResponse = IParsedResponse>(data:
status: data.playabilityStatus.status,
reason: data.playabilityStatus.reason || '',
embeddable: !!data.playabilityStatus.playableInEmbed || false,
audio_only_playablility: parseItem(data.playabilityStatus.audioOnlyPlayability, AudioOnlyPlayability),
audio_only_playability: parseItem(data.playabilityStatus.audioOnlyPlayability, AudioOnlyPlayability),
error_screen: parseItem(data.playabilityStatus.errorScreen)
} : null;

Expand Down Expand Up @@ -716,13 +718,15 @@ export function parseRR(actions: RawNode[]) {
return observe(actions.map((action: any) => {
if (action.navigateAction)
return new NavigateAction(action.navigateAction);
if (action.showMiniplayerCommand)
else if (action.showMiniplayerCommand)
return new ShowMiniplayerCommand(action.showMiniplayerCommand);
if (action.reloadContinuationItemsCommand)
else if (action.reloadContinuationItemsCommand)
return new ReloadContinuationItemsCommand(action.reloadContinuationItemsCommand);
if (action.appendContinuationItemsAction)
return new YTNodes.AppendContinuationItemsAction(action.appendContinuationItemsAction);
}).filter((item) => item) as (ReloadContinuationItemsCommand | YTNodes.AppendContinuationItemsAction)[]);
else if (action.appendContinuationItemsAction)
return new AppendContinuationItemsAction(action.appendContinuationItemsAction);
else if (action.openPopupAction)
return new OpenPopupAction(action.openPopupAction);
}).filter((item) => item) as (AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand)[]);
}

export function parseActions(data: RawData) {
Expand Down
14 changes: 8 additions & 6 deletions src/parser/types/ParsedResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Memo, ObservedArray, SuperParsedResult, YTNode } from '../helpers.
import type {
ReloadContinuationItemsCommand, Continuation, GridContinuation,
ItemSectionContinuation, LiveChatContinuation, MusicPlaylistShelfContinuation, MusicShelfContinuation,
PlaylistPanelContinuation, SectionListContinuation, ContinuationCommand
PlaylistPanelContinuation, SectionListContinuation, ContinuationCommand, ShowMiniplayerCommand, NavigateAction
} from '../index.js';

import type { CpnSource } from './RawResponse.js';
Expand All @@ -19,7 +19,9 @@ 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';
import type { AppendContinuationItemsAction, MusicThumbnail } from '../nodes.js';
import type AppendContinuationItemsAction from '../classes/actions/AppendContinuationItemsAction.js';
import type MusicThumbnail from '../classes/MusicThumbnail.js';
import type OpenPopupAction from '../classes/actions/OpenPopupAction.js';

export interface IParsedResponse {
background?: MusicThumbnail;
Expand All @@ -34,11 +36,11 @@ export interface IParsedResponse {
live_chat_item_context_menu_supported_renderers?: YTNode;
live_chat_item_context_menu_supported_renderers_memo?: Memo;
items_memo?: Memo;
on_response_received_actions?: ObservedArray<ReloadContinuationItemsCommand | AppendContinuationItemsAction>;
on_response_received_actions?: ObservedArray<AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand>;
on_response_received_actions_memo?: Memo;
on_response_received_endpoints?: ObservedArray<ReloadContinuationItemsCommand | AppendContinuationItemsAction>;
on_response_received_endpoints?: ObservedArray<AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand>;
on_response_received_endpoints_memo?: Memo;
on_response_received_commands?: ObservedArray<ReloadContinuationItemsCommand | AppendContinuationItemsAction>;
on_response_received_commands?: ObservedArray<AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand>;
on_response_received_commands_memo?: Memo;
continuation?: Continuation;
continuation_contents?: ItemSectionContinuation | SectionListContinuation | LiveChatContinuation | MusicPlaylistShelfContinuation |
Expand Down Expand Up @@ -83,7 +85,7 @@ export interface IPlaybackTracking {
export interface IPlayabilityStatus {
status: string;
error_screen: YTNode | null;
audio_only_playablility: AudioOnlyPlayability | null;
audio_only_playability: AudioOnlyPlayability | null;
embeddable: boolean;
reason: string;
}
Expand Down

0 comments on commit 45b7342

Please sign in to comment.