html data added in video_basic_info function
This commit is contained in:
parent
76ab060d57
commit
5214250eac
@ -50,6 +50,7 @@ let id = extractID(url)
|
|||||||
_This are the info options that can be passed as a parameter in `video_info` and `video_basic_info`_
|
_This are the info options that can be passed as a parameter in `video_info` and `video_basic_info`_
|
||||||
|
|
||||||
- proxy : Optional parameter to add support of proxies. As of now, HTTPS proxies are only supported. So make sure to get HTTPS proxies only.
|
- proxy : Optional parameter to add support of proxies. As of now, HTTPS proxies are only supported. So make sure to get HTTPS proxies only.
|
||||||
|
- htmldata : `boolean` Set this to true if you are passing a html body as first parameter.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const video = await video_basic_info(url, { proxy : ['url'] }) // Accepts a url which has port in it.
|
const video = await video_basic_info(url, { proxy : ['url'] }) // Accepts a url which has port in it.
|
||||||
@ -59,6 +60,10 @@ const video = await video_basic_info(url, {proxy : [{
|
|||||||
port : 8080
|
port : 8080
|
||||||
}]
|
}]
|
||||||
}) // Or add a json containing hostname and port.
|
}) // Or add a json containing hostname and port.
|
||||||
|
|
||||||
|
// Use any https package to use proxy and then do this
|
||||||
|
|
||||||
|
const video = await video_basic_info(body, { htmldata : true }) // You can use video_info function also.
|
||||||
```
|
```
|
||||||
|
|
||||||
### video_basic_info(url : `string`, options? : [`InfoOptions`](https://github.com/play-dl/play-dl/tree/main/docs/YouTube#infooptions))
|
### video_basic_info(url : `string`, options? : [`InfoOptions`](https://github.com/play-dl/play-dl/tree/main/docs/YouTube#infooptions))
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import http, { ClientRequest, IncomingMessage } from 'node:http';
|
import http, { ClientRequest, IncomingMessage } from 'node:http';
|
||||||
import https, { RequestOptions } from 'node:https';
|
import https, { RequestOptions } from 'node:https';
|
||||||
import { URL } from 'node:url';
|
import { URL } from 'node:url';
|
||||||
import { getCookies, setCookie, uploadCookie } from '../YouTube/utils/cookie';
|
import { cookieHeaders, getCookies } from '../YouTube/utils/cookie';
|
||||||
import { Proxy } from './classes';
|
import { Proxy } from './classes';
|
||||||
|
|
||||||
export type ProxyOptions = ProxyOpts | string;
|
export type ProxyOptions = ProxyOpts | string;
|
||||||
@ -63,16 +63,7 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (res.headers && res.headers['set-cookie'] && cookies_added) {
|
if (res.headers && res.headers['set-cookie'] && cookies_added) {
|
||||||
res.headers['set-cookie'].forEach((x) => {
|
cookieHeaders(res.headers['set-cookie'])
|
||||||
x.split(';').forEach((x) => {
|
|
||||||
const arr = x.split('=');
|
|
||||||
if (arr.length <= 1) return;
|
|
||||||
const key = arr.shift()?.trim() as string;
|
|
||||||
const value = arr.join('=').trim();
|
|
||||||
setCookie(key, value);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
uploadCookie();
|
|
||||||
}
|
}
|
||||||
if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) {
|
if (Number(res.statusCode) >= 300 && Number(res.statusCode) < 400) {
|
||||||
res = await https_getter(res.headers.location as string, options);
|
res = await https_getter(res.headers.location as string, options);
|
||||||
@ -98,16 +89,7 @@ export function request(req_url: string, options: RequestOpts = { method: 'GET'
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (res.headers && (res.headers as any)['set-cookie'] && cookies_added) {
|
if (res.headers && (res.headers as any)['set-cookie'] && cookies_added) {
|
||||||
(res.headers as any)['set-cookie'].forEach((x: string) => {
|
cookieHeaders((res.headers as any)['set-cookie'])
|
||||||
x.split(';').forEach((x) => {
|
|
||||||
const arr = x.split('=');
|
|
||||||
if (arr.length <= 1) return;
|
|
||||||
const key = arr.shift()?.trim() as string;
|
|
||||||
const value = arr.join('=').trim();
|
|
||||||
setCookie(key, value);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
uploadCookie();
|
|
||||||
}
|
}
|
||||||
if (res.statusCode >= 300 && res.statusCode < 400) {
|
if (res.statusCode >= 300 && res.statusCode < 400) {
|
||||||
res = await proxy_getter((res.headers as any)['location'], options.proxies, options.headers);
|
res = await proxy_getter((res.headers as any)['location'], options.proxies, options.headers);
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
export { stream, stream_from_info, YouTubeStream } from './stream';
|
export { stream, stream_from_info, YouTubeStream } from './stream';
|
||||||
export * from './utils';
|
export * from './utils';
|
||||||
export { YouTube } from './search';
|
export { YouTube } from './search';
|
||||||
|
export { cookieHeaders } from './utils/cookie'
|
||||||
@ -13,6 +13,7 @@ export enum StreamType {
|
|||||||
export interface StreamOptions {
|
export interface StreamOptions {
|
||||||
quality?: number;
|
quality?: number;
|
||||||
proxy?: Proxy[];
|
proxy?: Proxy[];
|
||||||
|
htmldata? : boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InfoData {
|
export interface InfoData {
|
||||||
@ -53,7 +54,7 @@ export type YouTubeStream = Stream | LiveStreaming;
|
|||||||
* @returns Stream class with type and stream for playing.
|
* @returns Stream class with type and stream for playing.
|
||||||
*/
|
*/
|
||||||
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream> {
|
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream> {
|
||||||
const info = await video_info(url, { proxy: options.proxy });
|
const info = await video_info(url, { proxy: options.proxy, htmldata : options.htmldata });
|
||||||
const final: any[] = [];
|
const final: any[] = [];
|
||||||
if (
|
if (
|
||||||
info.LiveStreamData.isLive === true &&
|
info.LiveStreamData.isLive === true &&
|
||||||
|
|||||||
@ -46,3 +46,16 @@ export function setCookieToken(options: { cookie: string }) {
|
|||||||
youtubeData = { cookie };
|
youtubeData = { cookie };
|
||||||
youtubeData.file = false;
|
youtubeData.file = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cookieHeaders(headCookie : string[]){
|
||||||
|
headCookie.forEach((x: string) => {
|
||||||
|
x.split(';').forEach((x) => {
|
||||||
|
const arr = x.split('=');
|
||||||
|
if (arr.length <= 1) return;
|
||||||
|
const key = arr.shift()?.trim() as string;
|
||||||
|
const value = arr.join('=').trim();
|
||||||
|
setCookie(key, value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
uploadCookie();
|
||||||
|
}
|
||||||
@ -6,6 +6,7 @@ import { InfoData } from '../stream';
|
|||||||
|
|
||||||
interface InfoOptions {
|
interface InfoOptions {
|
||||||
proxy?: Proxy[];
|
proxy?: Proxy[];
|
||||||
|
htmldata? : boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlaylistOptions {
|
interface PlaylistOptions {
|
||||||
@ -79,14 +80,20 @@ export function extractID(url: string): string {
|
|||||||
* @returns Data containing video_details, LiveStreamData and formats of video url.
|
* @returns Data containing video_details, LiveStreamData and formats of video url.
|
||||||
*/
|
*/
|
||||||
export async function video_basic_info(url: string, options: InfoOptions = {}) {
|
export async function video_basic_info(url: string, options: InfoOptions = {}) {
|
||||||
if (yt_validate(url) !== 'video') throw new Error('This is not a YouTube Watch URL');
|
let body : string;
|
||||||
const video_id: string = extractID(url);
|
if(options.htmldata){
|
||||||
const new_url = `https://www.youtube.com/watch?v=${video_id}&has_verified=1`;
|
body = url;
|
||||||
const body = await request(new_url, {
|
}
|
||||||
proxies: options.proxy ?? [],
|
else {
|
||||||
headers: { 'accept-language': 'en-US,en-IN;q=0.9,en;q=0.8,hi;q=0.7' },
|
if (yt_validate(url) !== 'video') throw new Error('This is not a YouTube Watch URL');
|
||||||
cookies: true
|
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' },
|
||||||
|
cookies: true
|
||||||
|
});
|
||||||
|
}
|
||||||
const player_data = body
|
const player_data = body
|
||||||
.split('var ytInitialPlayerResponse = ')?.[1]
|
.split('var ytInitialPlayerResponse = ')?.[1]
|
||||||
?.split(';</script>')[0]
|
?.split(';</script>')[0]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user