Added Seek Support

This commit is contained in:
killer069
2021-12-13 09:45:34 +05:30
parent 5a094be82e
commit f2598c9a7c
5 changed files with 460 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import { LiveStream, Stream } from './classes/LiveStream';
import { SeekStream } from './classes/SeekStream';
import { InfoData, StreamInfoData } from './utils/constants';
import { video_stream_info } from './utils/extractor';
@@ -11,6 +12,7 @@ export enum StreamType {
}
export interface StreamOptions {
seek? : number
quality?: number;
htmldata?: boolean;
}
@@ -35,7 +37,7 @@ export function parseAudioFormats(formats: any[]) {
/**
* Type for YouTube Stream
*/
export type YouTubeStream = Stream | LiveStream;
export type YouTubeStream = Stream | LiveStream | SeekStream;
/**
* Stream command for YouTube
* @param url YouTube URL
@@ -77,7 +79,19 @@ export async function stream_from_info(
else final.push(info.format[info.format.length - 1]);
let type: StreamType =
final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary;
return new Stream(
if(options.seek){
if(type === StreamType.WebmOpus) {
return new SeekStream(
final[0].url,
info.video_details.durationInSec,
Number(final[0].contentLength),
info.video_details.url,
options
)
}
else throw new Error("Seek is only supported in Webm Opus Files.")
}
else return new Stream(
final[0].url,
type,
info.video_details.durationInSec,