mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
feat: Add support for retrieving transcripts (#500)
* feat: Add support for retrieving transcripts * chore: lint * chore: update docs * chore: Do not include nodes in errors thrown * chore: Improve error messages * fix(ExpandableMetadata): `expanded_content` type mismatch * chore: lint
This commit is contained in:
@@ -7,6 +7,7 @@ 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 EngagementPanelSectionList from './classes/EngagementPanelSectionList.js';
|
||||
|
||||
import type { IParsedResponse, IRawResponse, RawData, RawNode } from './types/index.js';
|
||||
|
||||
@@ -21,7 +22,13 @@ import { Memo, observe, SuperParsedResult } from './helpers.js';
|
||||
import * as YTNodes from './nodes.js';
|
||||
import type { KeyInfo } from './generator.js';
|
||||
import { camelToSnake, generateRuntimeClass, generateTypescriptClass } from './generator.js';
|
||||
import { Continuation, ItemSectionContinuation, SectionListContinuation, LiveChatContinuation, MusicPlaylistShelfContinuation, MusicShelfContinuation, GridContinuation, PlaylistPanelContinuation, NavigateAction, ShowMiniplayerCommand, ReloadContinuationItemsCommand } from './continuations.js';
|
||||
|
||||
import {
|
||||
Continuation, ItemSectionContinuation, SectionListContinuation,
|
||||
LiveChatContinuation, MusicPlaylistShelfContinuation, MusicShelfContinuation,
|
||||
GridContinuation, PlaylistPanelContinuation, NavigateAction, ShowMiniplayerCommand,
|
||||
ReloadContinuationItemsCommand
|
||||
} from './continuations.js';
|
||||
|
||||
export type ParserError = {
|
||||
classname: string,
|
||||
@@ -289,6 +296,14 @@ export function parseResponse<T extends IParsedResponse = IParsedResponse>(data:
|
||||
}
|
||||
_clearMemo();
|
||||
|
||||
_createMemo();
|
||||
const items = parse(data.items);
|
||||
if (items) {
|
||||
parsed_data.items = items;
|
||||
parsed_data.items_memo = _getMemo();
|
||||
}
|
||||
_clearMemo();
|
||||
|
||||
applyMutations(contents_memo, data.frameworkUpdates?.entityBatchUpdate?.mutations);
|
||||
|
||||
const continuation = data.continuation ? parseC(data.continuation) : null;
|
||||
@@ -404,20 +419,10 @@ export function parseResponse<T extends IParsedResponse = IParsedResponse>(data:
|
||||
parsed_data.cards = cards;
|
||||
}
|
||||
|
||||
const engagement_panels = data.engagementPanels?.map((e) => {
|
||||
const item = parseItem(e, YTNodes.EngagementPanelSectionList) as YTNodes.EngagementPanelSectionList;
|
||||
return item;
|
||||
});
|
||||
if (engagement_panels) {
|
||||
const engagement_panels = parseArray(data.engagementPanels, EngagementPanelSectionList);
|
||||
if (engagement_panels.length) {
|
||||
parsed_data.engagement_panels = engagement_panels;
|
||||
}
|
||||
_createMemo();
|
||||
const items = parse(data.items);
|
||||
if (items) {
|
||||
parsed_data.items = items;
|
||||
parsed_data.items_memo = _getMemo();
|
||||
}
|
||||
_clearMemo();
|
||||
|
||||
return parsed_data;
|
||||
}
|
||||
@@ -429,7 +434,7 @@ export function parseResponse<T extends IParsedResponse = IParsedResponse>(data:
|
||||
*/
|
||||
export function parseItem<T extends YTNode, K extends YTNodeConstructor<T>[]>(data: RawNode | undefined, validTypes: K): InstanceType<K[number]> | null;
|
||||
export function parseItem<T extends YTNode>(data: RawNode | undefined, validTypes: YTNodeConstructor<T>): T | null;
|
||||
export function parseItem(data?: RawNode) : YTNode;
|
||||
export function parseItem(data?: RawNode): YTNode;
|
||||
export function parseItem(data?: RawNode, validTypes?: YTNodeConstructor | YTNodeConstructor[]) {
|
||||
if (!data) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user