Cookies Header function added

This commit is contained in:
killer069
2021-11-01 15:32:51 +05:30
parent 5214250eac
commit 703e36c78d
7 changed files with 24 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
export { stream, stream_from_info, YouTubeStream } from './stream';
export * from './utils';
export { YouTube } from './search';
export { cookieHeaders } from './utils/cookie'
export { cookieHeaders } from './utils/cookie';

View File

@@ -13,7 +13,7 @@ export enum StreamType {
export interface StreamOptions {
quality?: number;
proxy?: Proxy[];
htmldata? : boolean
htmldata?: boolean;
}
export interface InfoData {
@@ -54,7 +54,7 @@ export type YouTubeStream = Stream | LiveStreaming;
* @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, { proxy: options.proxy, htmldata: options.htmldata });
const final: any[] = [];
if (
info.LiveStreamData.isLive === true &&

View File

@@ -47,7 +47,8 @@ export function setCookieToken(options: { cookie: string }) {
youtubeData.file = false;
}
export function cookieHeaders(headCookie : string[]){
export function cookieHeaders(headCookie: string[]) {
if (!youtubeData?.cookie) return;
headCookie.forEach((x: string) => {
x.split(';').forEach((x) => {
const arr = x.split('=');
@@ -58,4 +59,4 @@ export function cookieHeaders(headCookie : string[]){
});
});
uploadCookie();
}
}

View File

@@ -6,7 +6,7 @@ import { InfoData } from '../stream';
interface InfoOptions {
proxy?: Proxy[];
htmldata? : boolean
htmldata?: boolean;
}
interface PlaylistOptions {
@@ -80,11 +80,10 @@ export function extractID(url: string): string {
* @returns Data containing video_details, LiveStreamData and formats of video url.
*/
export async function video_basic_info(url: string, options: InfoOptions = {}) {
let body : string;
if(options.htmldata){
let body: string;
if (options.htmldata) {
body = url;
}
else {
} else {
if (yt_validate(url) !== 'video') throw new Error('This is not a YouTube Watch URL');
const video_id: string = extractID(url);
const new_url = `https://www.youtube.com/watch?v=${video_id}&has_verified=1`;