mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Added User agents support
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Readable } from 'node:stream';
|
||||
import { IncomingMessage } from 'node:http';
|
||||
import { parseAudioFormats, StreamOptions, StreamType } from '../stream';
|
||||
import { ProxyOptions as Proxy, request, request_stream } from '../../Request';
|
||||
import { request, request_stream } from '../../Request';
|
||||
import { video_info } from '..';
|
||||
|
||||
export interface FormatInterface {
|
||||
@@ -230,10 +230,6 @@ export class Stream {
|
||||
* Quality given by user. [ Used only for retrying purposes only. ]
|
||||
*/
|
||||
private quality: number;
|
||||
/**
|
||||
* Proxy config given by user. [ Used only for retrying purposes only. ]
|
||||
*/
|
||||
private proxy: Proxy[] | undefined;
|
||||
/**
|
||||
* Incoming message that we recieve.
|
||||
*
|
||||
@@ -261,7 +257,6 @@ export class Stream {
|
||||
this.stream = new Readable({ highWaterMark: 5 * 1000 * 1000, read() {} });
|
||||
this.url = url;
|
||||
this.quality = options.quality as number;
|
||||
this.proxy = options.proxy || undefined;
|
||||
this.type = type;
|
||||
this.bytes_count = 0;
|
||||
this.video_url = video_url;
|
||||
@@ -282,7 +277,7 @@ export class Stream {
|
||||
* Retry if we get 404 or 403 Errors.
|
||||
*/
|
||||
private async retry() {
|
||||
const info = await video_info(this.video_url, { proxy: this.proxy });
|
||||
const info = await video_info(this.video_url);
|
||||
const audioFormat = parseAudioFormats(info.format);
|
||||
this.url = audioFormat[this.quality].url;
|
||||
}
|
||||
|
||||
@@ -40,9 +40,8 @@ export async function yt_search(search: string, options: ParseSearchInterface =
|
||||
}
|
||||
}
|
||||
const body = await request(url, {
|
||||
headers: {
|
||||
'accept-language': 'en-US,en;q=0.9',
|
||||
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
|
||||
headers: {
|
||||
'accept-language': 'en-US,en;q=0.9'
|
||||
}
|
||||
});
|
||||
if (body.indexOf('Our systems have detected unusual traffic from your computer network.') !== -1)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { video_info } from '.';
|
||||
import { LiveStream, Stream } from './classes/LiveStream';
|
||||
import { ProxyOptions as Proxy } from './../Request';
|
||||
import { InfoData } from './utils/constants';
|
||||
|
||||
export enum StreamType {
|
||||
@@ -13,7 +12,6 @@ export enum StreamType {
|
||||
|
||||
export interface StreamOptions {
|
||||
quality?: number;
|
||||
proxy?: Proxy[];
|
||||
htmldata?: boolean;
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ export type YouTubeStream = Stream | LiveStream;
|
||||
* @returns Stream class with type and stream for playing.
|
||||
*/
|
||||
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream> {
|
||||
const info = await video_info(url, { proxy: options.proxy, htmldata: options.htmldata });
|
||||
const info = await video_info(url, { htmldata: options.htmldata });
|
||||
return await stream_from_info(info, options);
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
import { ProxyOptions as Proxy, request } from './../../Request/index';
|
||||
import { request } from './../../Request/index';
|
||||
import { format_decipher } from './cipher';
|
||||
import { YouTubeVideo } from '../classes/Video';
|
||||
import { YouTubePlayList } from '../classes/Playlist';
|
||||
import { InfoData } from './constants';
|
||||
|
||||
interface InfoOptions {
|
||||
proxy?: Proxy[];
|
||||
htmldata?: boolean;
|
||||
}
|
||||
|
||||
interface PlaylistOptions {
|
||||
incomplete?: boolean;
|
||||
proxy?: Proxy[];
|
||||
}
|
||||
|
||||
const video_id_pattern = /^[a-zA-Z\d_-]{11,12}$/;
|
||||
@@ -123,11 +121,9 @@ export async function video_basic_info(url: string, options: InfoOptions = {}):
|
||||
const video_id: string = extractID(url);
|
||||
const new_url = `https://www.youtube.com/watch?v=${video_id}&has_verified=1`;
|
||||
body = await request(new_url, {
|
||||
proxies: options.proxy ?? [],
|
||||
headers: {
|
||||
'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7',
|
||||
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
|
||||
},
|
||||
headers: {
|
||||
'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7'
|
||||
},
|
||||
cookies: true
|
||||
});
|
||||
}
|
||||
@@ -325,10 +321,8 @@ export async function playlist_info(url: string, options: PlaylistOptions = {}):
|
||||
const new_url = `https://www.youtube.com/playlist?list=${Playlist_id}`;
|
||||
|
||||
const body = await request(new_url, {
|
||||
proxies: options.proxy ?? undefined,
|
||||
headers: {
|
||||
'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7',
|
||||
'user-agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
|
||||
headers: {
|
||||
'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7'
|
||||
}
|
||||
});
|
||||
if (body.indexOf('Our systems have detected unusual traffic from your computer network.') !== -1)
|
||||
|
||||
Reference in New Issue
Block a user