From f21f34ea315986220636d2481aface215c3c1e4e Mon Sep 17 00:00:00 2001 From: killer069 <65385476+killer069@users.noreply.github.com> Date: Mon, 27 Sep 2021 23:12:22 +0530 Subject: [PATCH] Added Proxy Options --- play-dl/YouTube/utils/request.ts | 10 ++++++++++ play-dl/index.ts | 13 +++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/play-dl/YouTube/utils/request.ts b/play-dl/YouTube/utils/request.ts index c502b73..ea972d6 100644 --- a/play-dl/YouTube/utils/request.ts +++ b/play-dl/YouTube/utils/request.ts @@ -2,9 +2,19 @@ import https, { RequestOptions } from 'https'; import { IncomingMessage } from 'http'; import { URL } from 'url'; +interface ProxyOpts { + host : string, + port : number, + authentication? : { + username : string; + password : string; + } +} + interface RequestOpts extends RequestOptions { body?: string; method?: 'GET' | 'POST'; + proxies? : string[] | ProxyOpts[] } function https_getter(req_url: string, options: RequestOpts = {}): Promise { diff --git a/play-dl/index.ts b/play-dl/index.ts index 57e4d4a..e7ffa77 100644 --- a/play-dl/index.ts +++ b/play-dl/index.ts @@ -13,7 +13,7 @@ interface SearchOptions { import readline from 'readline'; import fs from 'fs'; -import { sp_validate, yt_validate, so_validate, YouTubeStream, SoundCloudStream } from '.'; +import { sp_validate, yt_validate, so_validate, YouTubeStream, SoundCloudStream, YouTube, SoundCloud, Spotify } from '.'; import { SpotifyAuthorize, sp_search } from './Spotify'; import { check_id, so_search, stream as so_stream, stream_from_info as so_stream_info } from './SoundCloud'; import { InfoData, stream as yt_stream, StreamOptions, stream_from_info as yt_stream_info } from './YouTube/stream'; @@ -30,7 +30,7 @@ import { yt_search } from './YouTube/search'; export async function stream(url: string, options: StreamOptions = {}): Promise { if (url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.'); if (url.indexOf('soundcloud') !== -1) return await so_stream(url, options.quality); - else return await yt_stream(url, { cookie: options.cookie }); + else return await yt_stream(url, options); } /** @@ -39,16 +39,17 @@ export async function stream(url: string, options: StreamOptions = {}): Promise< * @param options contains limit and source to choose. * @returns */ -export async function search(query: string, options: SearchOptions = {}) { +export async function search(query: string, options: SearchOptions = {}): Promise { if (!options.source) options.source = { youtube: 'video' }; if (options.source.youtube) return await yt_search(query, { limit: options.limit, type: options.source.youtube }); else if (options.source.spotify) return await sp_search(query, options.source.spotify, options.limit); else if (options.source.soundcloud) return await so_search(query, options.source.soundcloud, options.limit); + else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.') } /** - * + * Command to be used * @param info * @param options * @returns @@ -57,8 +58,8 @@ export async function stream_from_info( info: InfoData | SoundCloudTrack, options: StreamOptions = {} ): Promise { - if (info instanceof SoundCloudTrack) return await so_stream_info(info); - else return await yt_stream_info(info, { cookie: options.cookie }); + if (info instanceof SoundCloudTrack) return await so_stream_info(info, options.quality); + else return await yt_stream_info(info, options); } export async function validate(