Search function fixed
This commit is contained in:
parent
e69f466f53
commit
f410483980
@ -156,7 +156,7 @@ export async function sp_search(
|
|||||||
if (query.length === 0) throw new Error('Pass some query to search.');
|
if (query.length === 0) throw new Error('Pass some query to search.');
|
||||||
if (limit > 50 || limit < 0) throw new Error(`You crossed limit range of Spotify [ 0 - 50 ]`);
|
if (limit > 50 || limit < 0) throw new Error(`You crossed limit range of Spotify [ 0 - 50 ]`);
|
||||||
const response = await request(
|
const response = await request(
|
||||||
`https://api.spotify.com/v1/search?type=${type}&q=${query.replaceAll(' ', '+')}&limit=${limit}&market=${
|
`https://api.spotify.com/v1/search?type=${type}&q=${query}&limit=${limit}&market=${
|
||||||
spotifyData.market
|
spotifyData.market
|
||||||
}`,
|
}`,
|
||||||
{
|
{
|
||||||
|
|||||||
@ -21,7 +21,7 @@ export type YouTube = YouTubeVideo | YouTubeChannel | YouTubePlayList;
|
|||||||
* @returns YouTube type.
|
* @returns YouTube type.
|
||||||
*/
|
*/
|
||||||
export async function yt_search(search: string, options: ParseSearchInterface = {}): Promise<YouTube[]> {
|
export async function yt_search(search: string, options: ParseSearchInterface = {}): Promise<YouTube[]> {
|
||||||
let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+');
|
let url = 'https://www.youtube.com/results?search_query=' + search;
|
||||||
options.type ??= 'video';
|
options.type ??= 'video';
|
||||||
if (!url.match('&sp=')) {
|
if (!url.match('&sp=')) {
|
||||||
url += '&sp=';
|
url += '&sp=';
|
||||||
|
|||||||
@ -77,7 +77,7 @@ export async function search(
|
|||||||
options: SearchOptions = {}
|
options: SearchOptions = {}
|
||||||
): Promise<YouTube[] | Spotify[] | SoundCloud[]> {
|
): Promise<YouTube[] | Spotify[] | SoundCloud[]> {
|
||||||
if (!options.source) options.source = { youtube: 'video' };
|
if (!options.source) options.source = { youtube: 'video' };
|
||||||
|
query = encodeURIComponent(query)
|
||||||
if (options.source.youtube) return await yt_search(query, { limit: options.limit, type: options.source.youtube });
|
if (options.source.youtube) return await yt_search(query, { limit: options.limit, type: options.source.youtube });
|
||||||
else if (options.source.spotify) return await sp_search(query, options.source.spotify, options.limit);
|
else if (options.source.spotify) return await sp_search(query, options.source.spotify, options.limit);
|
||||||
else if (options.source.soundcloud) return await so_search(query, options.source.soundcloud, options.limit);
|
else if (options.source.soundcloud) return await so_search(query, options.source.soundcloud, options.limit);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user