Merge pull request #184 from play-dl/developer

1.4.5
This commit is contained in:
Killer069
2021-12-07 10:54:05 +05:30
committed by GitHub
10 changed files with 90 additions and 312 deletions

View File

@@ -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;
}

View File

@@ -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)

View File

@@ -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;
}
@@ -41,17 +39,17 @@ export type YouTubeStream = Stream | LiveStream;
/**
* Stream command for YouTube
* @param url YouTube URL
* @param options lets you add quality, cookie, proxy support for stream
* @param options lets you add quality for stream
* @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);
}
/**
* Stream command for YouTube using info from video_info or decipher_info function.
* @param info video_info data
* @param options lets you add quality, cookie, proxy support for stream
* @param options lets you add quality for stream
* @returns Stream class with type and stream for playing.
*/
export async function stream_from_info(info: InfoData, options: StreamOptions = {}): Promise<YouTubeStream> {

View File

@@ -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, StreamInfoData } from './constants';
interface InfoOptions {
proxy?: Proxy[];
htmldata?: boolean;
}
interface PlaylistOptions {
incomplete?: boolean;
proxy?: Proxy[];
}
const video_id_pattern = /^[a-zA-Z\d_-]{11,12}$/;
@@ -93,24 +91,11 @@ export function extractID(url: string): string {
* const video = await play.video_basic_info('youtube video url')
*
* const res = ... // Any https package get function.
* const video = await play.video_basic_info(res.body, { htmldata : true })
*
* const video = await play.video_basic_info('youtube video url', { proxy : [{
host : "IP or hostname",
port : 8080,
authentication: {
username: 'username';
password: 'very secret';
}
}] }) // Authentication is optional.
// OR
const video = await play.video_basic_info('youtube video url', { proxy : ['url'] })
* const video = await play.video_basic_info(res.body, { htmldata : true })
* ```
* @param url YouTube url or ID or html body data
* @param options Video Info Options
* - `Proxy[]` proxy : sends data through a proxy
* - `boolean` htmldata : given data is html data or not
* @returns Video Basic Info {@link InfoData}.
*/
@@ -123,11 +108,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
});
}
@@ -309,24 +292,11 @@ function parseSeconds(seconds: number): string {
* const video = await play.video_info('youtube video url')
*
* const res = ... // Any https package get function.
* const video = await play.video_info(res.body, { htmldata : true })
*
* const video = await play.video_info('youtube video url', { proxy : [{
host : "IP or hostname",
port : 8080,
authentication: {
username: 'username';
password: 'very secret';
}
}] }) // Authentication is optional.
// OR
const video = await play.video_info('youtube video url', { proxy : ['url'] })
* const video = await play.video_info(res.body, { htmldata : true })
* ```
* @param url YouTube url or ID or html body data
* @param options Video Info Options
* - `Proxy[]` proxy : sends data through a proxy
* - `boolean` htmldata : given data is html data or not
* @returns Deciphered Video Info {@link InfoData}.
*/
@@ -357,24 +327,10 @@ export async function decipher_info<T extends InfoData | StreamInfoData>(data: T
* const playlist = await play.playlist_info('youtube playlist url')
*
* const playlist = await play.playlist_info('youtube playlist url', { incomplete : true })
*
* const playlist = await play.playlist_info('youtube playlist url', { proxy : [{
host : "IP or hostname",
port : 8080,
authentication: {
username: 'username';
password: 'very secret';
}
}] }) // Authentication is optional.
// OR
const playlist = await play.playlist_info('youtube playlist url', { proxy : ['url'] })
* ```
* @param url Playlist URL
* @param options Playlist Info Options
* - `boolean` incomplete : If set to true, parses playlist with hidden videos.
* - `Proxy[]` proxy : sends data through a proxy
*
* @returns YouTube Playlist
*/
@@ -388,10 +344,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)