mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-23 14:38:07 +00:00
feat(music#getSearchSuggestions)!: Return array of SearchSuggestionsSection instead of a single node
This commit is contained in:
@@ -20,7 +20,7 @@ import SectionList from '../../parser/classes/SectionList.js';
|
||||
import Tab from '../../parser/classes/Tab.js';
|
||||
import * as Proto from '../../proto/index.js';
|
||||
|
||||
import type { ObservedArray, YTNode } from '../../parser/helpers.js';
|
||||
import type { ObservedArray } from '../../parser/helpers.js';
|
||||
import type { MusicSearchFilters } from '../../types/index.js';
|
||||
import { InnertubeError, generateRandomString, throwIfMissing } from '../../utils/Utils.js';
|
||||
import type Actions from '../Actions.js';
|
||||
@@ -72,7 +72,7 @@ export default class Music {
|
||||
|
||||
const player_response = this.#actions.execute(PlayerEndpoint.PATH, player_payload);
|
||||
const next_response = this.#actions.execute(NextEndpoint.PATH, next_payload);
|
||||
const response = await Promise.all([ player_response, next_response ]);
|
||||
const response = await Promise.all([player_response, next_response]);
|
||||
|
||||
const cpn = generateRandomString(16);
|
||||
|
||||
@@ -105,7 +105,7 @@ export default class Music {
|
||||
|
||||
const cpn = generateRandomString(16);
|
||||
|
||||
const response = await Promise.all([ player_response, next_response ]);
|
||||
const response = await Promise.all([player_response, next_response]);
|
||||
return new TrackInfo(response, this.#actions, cpn);
|
||||
}
|
||||
|
||||
@@ -355,17 +355,17 @@ export default class Music {
|
||||
* Retrieves search suggestions for the given query.
|
||||
* @param query - The query.
|
||||
*/
|
||||
async getSearchSuggestions(query: string): Promise<ObservedArray<YTNode>> {
|
||||
async getSearchSuggestions(query: string): Promise<ObservedArray<SearchSuggestionsSection>> {
|
||||
const response = await this.#actions.execute(
|
||||
GetSearchSuggestionsEndpoint.PATH,
|
||||
{ ...GetSearchSuggestionsEndpoint.build({ input: query }), parse: true }
|
||||
);
|
||||
|
||||
if (!response.contents_memo)
|
||||
throw new InnertubeError('Unexpected response', response);
|
||||
return [] as unknown as ObservedArray<SearchSuggestionsSection>;
|
||||
|
||||
const search_suggestions_section = response.contents_memo.getType(SearchSuggestionsSection).first();
|
||||
const search_suggestions_sections = response.contents_memo.getType(SearchSuggestionsSection);
|
||||
|
||||
return search_suggestions_section.contents;
|
||||
return search_suggestions_sections;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user