pretty codes and LiveStream issues fixed 100%

This commit is contained in:
killer069
2021-09-28 21:05:43 +05:30
parent 9ab641d1f0
commit 20984ce9e9
5 changed files with 120 additions and 96 deletions

View File

@@ -1,5 +1,6 @@
import { video_info } from '.';
import { LiveStreaming, Stream } from './classes/LiveStream';
import { Proxy } from './utils/request';
export enum StreamType {
Arbitrary = 'arbitrary',
@@ -12,6 +13,7 @@ export enum StreamType {
export interface StreamOptions {
quality?: number;
cookie?: string;
proxy?: Proxy[];
}
export interface InfoData {
@@ -25,7 +27,7 @@ export interface InfoData {
video_details: any;
}
function parseAudioFormats(formats: any[]) {
export function parseAudioFormats(formats: any[]) {
const result: any[] = [];
formats.forEach((format) => {
const type = format.mimeType as string;
@@ -41,7 +43,7 @@ function parseAudioFormats(formats: any[]) {
export type YouTubeStream = Stream | LiveStreaming;
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream> {
const info = await video_info(url, { cookie : options.cookie });
const info = await video_info(url, { cookie: options.cookie, proxy: options.proxy });
const final: any[] = [];
if (
info.LiveStreamData.isLive === true &&
@@ -70,7 +72,8 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
info.video_details.durationInSec,
Number(final[0].contentLength),
info.video_details.url,
options.cookie as string
options.cookie as string,
options.quality
);
}
@@ -103,6 +106,7 @@ export async function stream_from_info(info: InfoData, options: StreamOptions =
info.video_details.durationInSec,
Number(final[0].contentLength),
info.video_details.url,
options.cookie as string
options.cookie as string,
options.quality
);
}