YouTube : Completed

This commit is contained in:
killer069
2021-08-13 13:16:34 +05:30
parent 455c7dfb69
commit 04770cc929
10 changed files with 215 additions and 76 deletions

View File

@@ -6,8 +6,29 @@ import { Channel } from "./classes/Channel";
import { PlayList } from "./classes/Playlist";
export async function search(url:string, options? : ParseSearchInterface): Promise<(Video | Channel | PlayList)[]> {
enum SearchType {
Video = 'EgIQAQ%253D%253D',
PlayList = 'EgIQAw%253D%253D',
Channel = 'EgIQAg%253D%253D',
}
export async function search(search :string, options? : ParseSearchInterface): Promise<(Video | Channel | PlayList)[]> {
let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+')
if(!url.match('&sp=')){
url += '&sp='
switch(options?.type){
case 'channel':
url += SearchType.Channel
break
case 'playlist':
url += SearchType.PlayList
break
case 'video':
url += SearchType.Video
break
}
}
let body = await url_get(url)
let data = ParseSearchResult(body)
let data = ParseSearchResult(body, options)
return data
}