From f4104839808674f9d7fa04dddc13f3fbbe566fda Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Thu, 21 Oct 2021 14:54:53 +0530 Subject: [PATCH] Search function fixed --- play-dl/Spotify/index.ts | 2 +- play-dl/YouTube/search.ts | 2 +- play-dl/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/play-dl/Spotify/index.ts b/play-dl/Spotify/index.ts index 39d5e3d..af83c08 100644 --- a/play-dl/Spotify/index.ts +++ b/play-dl/Spotify/index.ts @@ -156,7 +156,7 @@ export async function sp_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 ]`); 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 }`, { diff --git a/play-dl/YouTube/search.ts b/play-dl/YouTube/search.ts index de952e3..7f9fedc 100644 --- a/play-dl/YouTube/search.ts +++ b/play-dl/YouTube/search.ts @@ -21,7 +21,7 @@ export type YouTube = YouTubeVideo | YouTubeChannel | YouTubePlayList; * @returns YouTube type. */ export async function yt_search(search: string, options: ParseSearchInterface = {}): Promise { - let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+'); + let url = 'https://www.youtube.com/results?search_query=' + search; options.type ??= 'video'; if (!url.match('&sp=')) { url += '&sp='; diff --git a/play-dl/index.ts b/play-dl/index.ts index 91ca3a4..b92f26c 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -77,7 +77,7 @@ export async function search( options: SearchOptions = {} ): Promise { 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 }); 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);