From 9a777e30ff85dbe911e2cc60ae420d651fc47813 Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Tue, 14 Sep 2021 22:11:02 +0530 Subject: [PATCH] optimize some code --- play-dl/YouTube/search.ts | 5 ++--- play-dl/YouTube/utils/request.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/play-dl/YouTube/search.ts b/play-dl/YouTube/search.ts index 251d955..100e547 100644 --- a/play-dl/YouTube/search.ts +++ b/play-dl/YouTube/search.ts @@ -11,10 +11,9 @@ enum SearchType { Channel = 'EgIQAg%253D%253D', } -export async function search(search :string, options? : ParseSearchInterface): Promise<(Video | Channel | PlayList)[]> { +export async function search(search :string, options : ParseSearchInterface = {}): Promise<(Video | Channel | PlayList)[]> { let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+') - if(!options) options = { type : "video"} - if(!options.type) options.type = "video" + options.type ??= "video" if(!url.match('&sp=')){ url += '&sp=' switch(options?.type){ diff --git a/play-dl/YouTube/utils/request.ts b/play-dl/YouTube/utils/request.ts index 9164d9e..5b2c13a 100644 --- a/play-dl/YouTube/utils/request.ts +++ b/play-dl/YouTube/utils/request.ts @@ -7,7 +7,7 @@ interface RequestOpts extends RequestOptions{ method? : "GET" | "POST" } -async function https_getter(req_url : string, options : RequestOpts = {}): Promise{ +function https_getter(req_url : string, options : RequestOpts = {}): Promise{ return new Promise((resolve, reject) => { let s = new URL(req_url) options.method ??= "GET"