mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-30 09:55:18 +00:00
chore: update type definitions
This commit is contained in:
@@ -43,7 +43,7 @@ class NavigationEndpoint {
|
||||
params: data?.watchEndpoint.params || null,
|
||||
index: data?.watchEndpoint.index || null,
|
||||
supported_onesie_config: data?.watchEndpoint?.watchEndpointSupportedOnesieConfig,
|
||||
music_video_type: configs.musicVideoType
|
||||
music_video_type: configs?.musicVideoType || null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const Parser = require('../contents');
|
||||
const { InnertubeError } = require('../../utils/Utils');
|
||||
const { InnertubeError, observe } = require('../../utils/Utils');
|
||||
|
||||
/** @namespace */
|
||||
class Search {
|
||||
@@ -26,6 +26,7 @@ class Search {
|
||||
const contents = this.#page.contents?.primary_contents.contents
|
||||
|| this.#page.on_response_received_commands[0].continuation_items;
|
||||
|
||||
/** @type {object[]} */
|
||||
this.results = contents.get({ type: 'itemSectionRenderer' }).contents;
|
||||
|
||||
const shelves = this.results.findAll({ type: 'shelfRenderer' }, true);
|
||||
@@ -34,19 +35,26 @@ class Search {
|
||||
this.refinements = this.#page.refinements || [];
|
||||
this.estimated_results = this.#page.estimated_results;
|
||||
|
||||
this.sections = shelves.map((shelf) => ({
|
||||
/** @type {{ sections: { title: string; items: object[]; }[] }} */
|
||||
this.sections = observe(shelves.map((shelf) => ({
|
||||
title: shelf.title.toString(),
|
||||
items: shelf.content.items
|
||||
}));
|
||||
})));
|
||||
|
||||
this.refinement_cards = {
|
||||
/** @type {import('../contents/classes/RichListHeader')} */
|
||||
header: card_list?.header || null,
|
||||
/** @type {import('../contents/classes/SearchRefinementCard')} */
|
||||
cards: card_list?.cards || []
|
||||
};
|
||||
|
||||
this.#continuation = contents.get({ type: 'continuationItemRenderer' });
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves next batch of results.
|
||||
* @returns {Promise.<Search>}
|
||||
*/
|
||||
async getContinuation() {
|
||||
const response = await this.#continuation.endpoint.call(this.#actions);
|
||||
return new Search(response, this.#actions, { is_continuation: true });
|
||||
@@ -54,8 +62,8 @@ class Search {
|
||||
|
||||
/**
|
||||
* Applies given refinement card and returns a new {@link Search} object.
|
||||
* @param {SearchRefinementCard || string} refinement card object or query
|
||||
* @returns {Search}
|
||||
* @param {SearchRefinementCard | string} card - refinement card object or query
|
||||
* @returns {Promise.<Search>}
|
||||
*/
|
||||
async selectRefinementCard(card) {
|
||||
let target_card;
|
||||
@@ -76,18 +84,22 @@ class Search {
|
||||
return new Search(page, this.#actions, { is_continuation: true });
|
||||
}
|
||||
|
||||
/** @type {boolean} */
|
||||
get has_continuation() {
|
||||
return !!this.#continuation;
|
||||
}
|
||||
|
||||
/** @type {string[]} */
|
||||
get refinement_card_queries() {
|
||||
return this.refinement_cards.cards.map((card) => card.query);
|
||||
}
|
||||
|
||||
/** @type {import('../contents/classes/Video')[]} */
|
||||
get videos() {
|
||||
return this.results.findAll({ type: 'videoRenderer' });
|
||||
}
|
||||
|
||||
|
||||
/** @type {import('../contents/classes/Playlist')[]} */
|
||||
get playlists() {
|
||||
return this.results.findAll({ type: 'playlistRenderer' });
|
||||
}
|
||||
|
||||
39
typings/lib/parser/youtube/Search.d.ts
vendored
39
typings/lib/parser/youtube/Search.d.ts
vendored
@@ -11,25 +11,42 @@ declare class Search {
|
||||
constructor(response: object, actions: import('../../core/Actions'), args?: {
|
||||
is_continuation?: boolean;
|
||||
});
|
||||
results: any;
|
||||
/** @type {object[]} */
|
||||
results: object[];
|
||||
refinements: any;
|
||||
estimated_results: any;
|
||||
sections: any;
|
||||
refinement_cards: {
|
||||
header: any;
|
||||
cards: any;
|
||||
/** @type {{ sections: { title: string; items: object[]; }[] }} */
|
||||
sections: {
|
||||
sections: {
|
||||
title: string;
|
||||
items: object[];
|
||||
}[];
|
||||
};
|
||||
refinement_cards: {
|
||||
/** @type {import('../contents/classes/RichListHeader')} */
|
||||
header: import('../contents/classes/RichListHeader');
|
||||
/** @type {import('../contents/classes/SearchRefinementCard')} */
|
||||
cards: import('../contents/classes/SearchRefinementCard');
|
||||
};
|
||||
/**
|
||||
* Retrieves next batch of results.
|
||||
* @returns {Promise.<Search>}
|
||||
*/
|
||||
getContinuation(): Promise<Search>;
|
||||
/**
|
||||
* Applies given refinement card and returns a new {@link Search} object.
|
||||
* @param {SearchRefinementCard || string} refinement card object or query
|
||||
* @returns {Search}
|
||||
* @param {SearchRefinementCard | string} card - refinement card object or query
|
||||
* @returns {Promise.<Search>}
|
||||
*/
|
||||
selectRefinementCard(card: any): Search;
|
||||
selectRefinementCard(card: SearchRefinementCard | string): Promise<Search>;
|
||||
/** @type {boolean} */
|
||||
get has_continuation(): boolean;
|
||||
get refinement_card_queries(): any;
|
||||
get videos(): any;
|
||||
get playlists(): any;
|
||||
/** @type {string[]} */
|
||||
get refinement_card_queries(): string[];
|
||||
/** @type {import('../contents/classes/Video')[]} */
|
||||
get videos(): import("../contents/classes/Video")[];
|
||||
/** @type {import('../contents/classes/Playlist')[]} */
|
||||
get playlists(): import("../contents/classes/Playlist")[];
|
||||
get page(): any;
|
||||
#private;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user