import Tab from '../../parser/classes/Tab.js'; import Feed from './Feed.js'; import { InnertubeError } from '../../utils/Utils.js'; import type Actions from '../Actions.js'; import type { ObservedArray } from '../../parser/helpers.js'; import type { IParsedResponse } from '../../parser/types/ParsedResponse.js'; import type { ApiResponse } from '../Actions.js'; export default class TabbedFeed extends Feed { #tabs?: ObservedArray; #actions: Actions; constructor(actions: Actions, data: ApiResponse | IParsedResponse, already_parsed = false) { super(actions, data, already_parsed); this.#actions = actions; this.#tabs = this.page.contents_memo?.getType(Tab); } get tabs(): string[] { return this.#tabs?.map((tab) => tab.title.toString()) ?? []; } async getTabByName(title: string): Promise> { const tab = this.#tabs?.find((tab) => tab.title.toLowerCase() === title.toLowerCase()); if (!tab) throw new InnertubeError(`Tab "${title}" not found`); if (tab.selected) return this; const response = await tab.endpoint.call(this.#actions); return new TabbedFeed(this.#actions, response, false); } async getTabByURL(url: string): Promise> { const tab = this.#tabs?.find((tab) => tab.endpoint.metadata.url?.split('/').pop() === url); if (!tab) throw new InnertubeError(`Tab "${url}" not found`); if (tab.selected) return this; const response = await tab.endpoint.call(this.#actions); return new TabbedFeed(this.#actions, response, false); } hasTabWithURL(url: string): boolean { return this.#tabs?.some((tab) => tab.endpoint.metadata.url?.split('/').pop() === url) ?? false; } get title(): string | undefined { return this.page.contents_memo?.getType(Tab)?.find((tab) => tab.selected)?.title.toString(); } }