mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Various YouTube search improvements
This commit is contained in:
@@ -23,9 +23,9 @@ export type YouTube = YouTubeVideo | YouTubeChannel | YouTubePlayList;
|
||||
export async function yt_search(search: string, options: ParseSearchInterface = {}): Promise<YouTube[]> {
|
||||
let url = 'https://www.youtube.com/results?search_query=' + search;
|
||||
options.type ??= 'video';
|
||||
if (!url.match('&sp=')) {
|
||||
if (url.indexOf('&sp=') === -1) {
|
||||
url += '&sp=';
|
||||
switch (options?.type) {
|
||||
switch (options.type) {
|
||||
case 'channel':
|
||||
url += SearchType.Channel;
|
||||
break;
|
||||
@@ -35,13 +35,14 @@ export async function yt_search(search: string, options: ParseSearchInterface =
|
||||
case 'video':
|
||||
url += SearchType.Video;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unknown search type: ${options.type}`);
|
||||
}
|
||||
}
|
||||
const body = await request(url, {
|
||||
headers: { 'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7' }
|
||||
headers: { 'accept-language': 'en-US,en;q=0.9' }
|
||||
});
|
||||
if (body.indexOf('Our systems have detected unusual traffic from your computer network.') !== -1)
|
||||
throw new Error('Captcha page: YouTube has detected that you are a bot!');
|
||||
const data = ParseSearchResult(body, options);
|
||||
return data;
|
||||
return ParseSearchResult(body, options);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user