SoundCloud work + prettier

This commit is contained in:
killer069
2021-09-17 14:36:32 +05:30
parent f9876ce5c5
commit 90b13629b4
21 changed files with 1615 additions and 1162 deletions

View File

@@ -1,36 +1,38 @@
import { request } from "./utils/request";
import { ParseSearchInterface, ParseSearchResult } from "./utils/parser";
import { Video } from "./classes/Video";
import { Channel } from "./classes/Channel";
import { PlayList } from "./classes/Playlist";
import { request } from './utils/request';
import { ParseSearchInterface, ParseSearchResult } from './utils/parser';
import { Video } from './classes/Video';
import { Channel } from './classes/Channel';
import { PlayList } from './classes/Playlist';
enum SearchType {
Video = 'EgIQAQ%253D%253D',
PlayList = 'EgIQAw%253D%253D',
Channel = 'EgIQAg%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(' ', '+')
options.type ??= "video"
if(!url.match('&sp=')){
url += '&sp='
switch(options?.type){
export async function search(
search: string,
options: ParseSearchInterface = {}
): Promise<(Video | Channel | PlayList)[]> {
let url = 'https://www.youtube.com/results?search_query=' + search.replaceAll(' ', '+');
options.type ??= 'video';
if (!url.match('&sp=')) {
url += '&sp=';
switch (options?.type) {
case 'channel':
url += SearchType.Channel
break
url += SearchType.Channel;
break;
case 'playlist':
url += SearchType.PlayList
break
url += SearchType.PlayList;
break;
case 'video':
url += SearchType.Video
break
url += SearchType.Video;
break;
}
}
let body = await request(url, {
headers : {'accept-language' : 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7'}
})
let data = ParseSearchResult(body, options)
return data
}
const body = await request(url, {
headers: { 'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7' }
});
const data = ParseSearchResult(body, options);
return data;
}