chore(parser): Fix continuation types

This commit is contained in:
Luan
2024-12-18 12:18:40 -03:00
parent 45b734288e
commit c3d4b2d60a
4 changed files with 21 additions and 9 deletions

View File

@@ -23,9 +23,15 @@ import SortFilterSubMenu from '../classes/SortFilterSubMenu.js';
import ContinuationItem from '../classes/ContinuationItem.js';
import NavigationEndpoint from '../classes/NavigationEndpoint.js';
import type { AppendContinuationItemsAction, ReloadContinuationItemsCommand } from '../index.js';
import type {
AppendContinuationItemsAction,
NavigateAction,
ReloadContinuationItemsCommand,
ShowMiniplayerCommand
} from '../index.js';
import type { ApiResponse, Actions } from '../../core/index.js';
import type { IBrowseResponse } from '../types/index.js';
import type OpenPopupAction from '../classes/actions/OpenPopupAction.js';
export default class Channel extends TabbedFeed<IBrowseResponse> {
public header?: C4TabbedHeader | CarouselHeader | InteractiveTabbedHeader | PageHeader;
@@ -291,7 +297,7 @@ export default class Channel extends TabbedFeed<IBrowseResponse> {
}
export class ChannelListContinuation extends Feed<IBrowseResponse> {
contents?: ReloadContinuationItemsCommand | AppendContinuationItemsAction;
contents?: AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand;
constructor(actions: Actions, data: ApiResponse | IBrowseResponse, already_parsed = false) {
super(actions, data, already_parsed);
@@ -310,7 +316,7 @@ export class ChannelListContinuation extends Feed<IBrowseResponse> {
export class FilteredChannelList extends FilterableFeed<IBrowseResponse> {
applied_filter?: ChipCloudChip;
contents?: ReloadContinuationItemsCommand | AppendContinuationItemsAction;
contents?: AppendContinuationItemsAction | OpenPopupAction | NavigateAction | ShowMiniplayerCommand | ReloadContinuationItemsCommand;
constructor(actions: Actions, data: ApiResponse | IBrowseResponse, already_parsed = false) {
super(actions, data, already_parsed);

View File

@@ -7,7 +7,8 @@ import CommentsHeader from '../classes/comments/CommentsHeader.js';
import CommentSimplebox from '../classes/comments/CommentSimplebox.js';
import CommentThread from '../classes/comments/CommentThread.js';
import ContinuationItem from '../classes/ContinuationItem.js';
import { ReloadContinuationItemsCommand } from '../index.js';
import AppendContinuationItemsAction from '../classes/actions/AppendContinuationItemsAction.js';
import type { Actions, ApiResponse } from '../../core/index.js';
import type { INextResponse } from '../types/index.js';
@@ -28,8 +29,8 @@ export default class Comments {
if (!contents)
throw new InnertubeError('Comments page did not have any content.');
const header_node = contents.at(0);
const body_node = contents.at(1);
const header_node = contents.at(0)?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand);
const body_node = contents.at(1)?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand);
this.header = header_node?.contents?.firstOfType(CommentsHeader);

View File

@@ -13,6 +13,8 @@ import { observe } from '../helpers.js';
import type { ApiResponse, Actions } from '../../core/index.js';
import type { ObservedArray, YTNode } from '../helpers.js';
import type { ISearchResponse } from '../types/index.js';
import { ReloadContinuationItemsCommand } from '../index.js';
import AppendContinuationItemsAction from '../classes/actions/AppendContinuationItemsAction.js';
export default class Search extends Feed<ISearchResponse> {
public header?: SearchHeader;
@@ -28,7 +30,7 @@ export default class Search extends Feed<ISearchResponse> {
const contents =
this.page.contents_memo?.getType(SectionList).first().contents ||
this.page.on_response_received_commands?.first().contents;
this.page.on_response_received_commands?.first().as(AppendContinuationItemsAction, ReloadContinuationItemsCommand).contents;
if (!contents)
throw new InnertubeError('No contents found in search response');

View File

@@ -27,6 +27,9 @@ import VideoDescriptionMusicSection from '../classes/VideoDescriptionMusicSectio
import LiveChatWrap from './LiveChat.js';
import type { RawNode } from '../index.js';
import { ReloadContinuationItemsCommand } from '../index.js';
import AppendContinuationItemsAction from '../classes/actions/AppendContinuationItemsAction.js';
import type { Actions, ApiResponse } from '../../core/index.js';
import type { ObservedArray, YTNode } from '../helpers.js';
@@ -160,7 +163,7 @@ export default class VideoInfo extends MediaInfo {
const response = await cloud_chip.endpoint?.call(this.actions, { parse: true });
const data = response?.on_response_received_endpoints?.get({ target_id: 'watch-next-feed' });
this.watch_next_feed = data?.contents;
this.watch_next_feed = data?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand).contents;
return this;
}
@@ -185,7 +188,7 @@ export default class VideoInfo extends MediaInfo {
if (!data)
throw new InnertubeError('AppendContinuationItemsAction not found');
this.watch_next_feed = data?.contents;
this.watch_next_feed = data?.as(AppendContinuationItemsAction, ReloadContinuationItemsCommand).contents;
if (this.watch_next_feed?.at(-1)?.is(ContinuationItem)) {
this.#watch_next_continuation = this.watch_next_feed.pop()?.as(ContinuationItem);
} else {