optimize some code
This commit is contained in:
parent
9ed0048792
commit
9a777e30ff
@ -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){
|
||||
|
||||
@ -7,7 +7,7 @@ interface RequestOpts extends RequestOptions{
|
||||
method? : "GET" | "POST"
|
||||
}
|
||||
|
||||
async function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
|
||||
function https_getter(req_url : string, options : RequestOpts = {}): Promise<IncomingMessage>{
|
||||
return new Promise((resolve, reject) => {
|
||||
let s = new URL(req_url)
|
||||
options.method ??= "GET"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user