feat: Add AccessibilityContext and CommandContext classes + improve type definitions and parsing logic across multiple nodes

This commit is contained in:
Luan
2025-03-03 03:22:07 -03:00
parent 5ef7ea8034
commit 923e9c28e3
27 changed files with 474 additions and 202 deletions

View File

@@ -13,7 +13,7 @@ import MicroformatData from '../classes/MicroformatData.js';
import SubscribeButton from '../classes/SubscribeButton.js';
import ExpandableTab from '../classes/ExpandableTab.js';
import SectionList from '../classes/SectionList.js';
import Tab from '../classes/Tab.js';
import type Tab from '../classes/Tab.js';
import PageHeader from '../classes/PageHeader.js';
import TwoColumnBrowseResults from '../classes/TwoColumnBrowseResults.js';
import ChipCloudChip from '../classes/ChipCloudChip.js';
@@ -62,7 +62,7 @@ export default class Channel extends TabbedFeed<IBrowseResponse> {
this.subscribe_button = this.page.header_memo?.getType(SubscribeButton)[0];
if (this.page.contents)
this.current_tab = this.page.contents.item().as(TwoColumnBrowseResults).tabs.array().filterType(Tab, ExpandableTab).get({ selected: true });
this.current_tab = this.page.contents.item().as(TwoColumnBrowseResults).tabs.get({ selected: true });
}
/**

View File

@@ -37,7 +37,7 @@ export default class History extends Feed<IBrowseResponse> {
for (const section of this.sections) {
for (const content of section.contents) {
const video = content as Video;
if (video.id === video_id && video.menu) {
if (video.video_id === video_id && video.menu) {
feedbackToken = video.menu.top_level_buttons[0].as(Button).endpoint.payload.feedbackToken;
break;
}

View File

@@ -11,7 +11,6 @@ import SettingsSwitch from '../classes/SettingsSwitch.js';
import CommentsHeader from '../classes/comments/CommentsHeader.js';
import ItemSectionHeader from '../classes/ItemSectionHeader.js';
import ItemSectionTabbedHeader from '../classes/ItemSectionTabbedHeader.js';
import Tab from '../classes/Tab.js';
import TwoColumnBrowseResults from '../classes/TwoColumnBrowseResults.js';
import type { ApiResponse, Actions } from '../../core/index.js';
@@ -34,7 +33,7 @@ export default class Settings {
if (!this.#page.contents)
throw new InnertubeError('Page contents not found');
const tab = this.#page.contents.item().as(TwoColumnBrowseResults).tabs.array().as(Tab).get({ selected: true });
const tab = this.#page.contents.item().as(TwoColumnBrowseResults).tabs.get({ selected: true });
if (!tab)
throw new InnertubeError('Target tab not found');

View File

@@ -215,6 +215,9 @@ export default class VideoInfo extends MediaInfo {
if (like_status === 'LIKE')
throw new InnertubeError('This video is already liked', { video_id: this.basic_info.id });
if (!button.default_button.on_tap)
throw new InnertubeError('onTap command not found', { video_id: this.basic_info.id });
const endpoint = new NavigationEndpoint(button.default_button.on_tap.payload.commands.find((cmd: RawNode) => cmd.innertubeCommand));
return await endpoint.call(this.actions);
@@ -252,6 +255,9 @@ export default class VideoInfo extends MediaInfo {
if (like_status === 'DISLIKE')
throw new InnertubeError('This video is already disliked', { video_id: this.basic_info.id });
if (!button.default_button.on_tap)
throw new InnertubeError('onTap command not found', { video_id: this.basic_info.id });
const endpoint = new NavigationEndpoint(button.default_button.on_tap.payload.commands.find((cmd: RawNode) => cmd.innertubeCommand));
return await endpoint.call(this.actions);
@@ -298,7 +304,10 @@ export default class VideoInfo extends MediaInfo {
if (!button || !button.toggled_button)
throw new InnertubeError('Like/Dislike button not found', { video_id: this.basic_info.id });
if (!button.toggled_button.on_tap)
throw new InnertubeError('onTap command not found', { video_id: this.basic_info.id });
const endpoint = new NavigationEndpoint(button.toggled_button.on_tap.payload.commands.find((cmd: RawNode) => cmd.innertubeCommand));
return await endpoint.call(this.actions);
@@ -401,7 +410,7 @@ export default class VideoInfo extends MediaInfo {
// If the song isn't in the video_lockup, it should be in the info_rows
song = lookup.video_lockup?.title?.toString();
// If the video id isn't in the video_lockup, it should be in the info_rows
videoId = lookup.video_lockup?.endpoint.payload.videoId;
videoId = lookup.video_lockup?.endpoint?.payload.videoId;
for (let i = 0; i < lookup.info_rows.length; i++) {
const info_row = lookup.info_rows[i];
if (info_row.info_row_expand_status_key === undefined) {