Some stream creation issues fixes

This commit is contained in:
killer069 2022-01-20 16:19:55 +05:30
parent b32307a095
commit c2fa754dee
2 changed files with 26 additions and 20 deletions

View File

@ -19,6 +19,7 @@ export interface StreamOptions {
language?: string; language?: string;
htmldata?: boolean; htmldata?: boolean;
precache?: number; precache?: number;
optimization?: boolean
} }
/** /**
@ -86,24 +87,27 @@ export async function stream_from_info(
final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary; final[0].codec === 'opus' && final[0].container === 'webm' ? StreamType.WebmOpus : StreamType.Arbitrary;
await request_stream(`https://${new URL(final[0].url).host}/generate_204`); await request_stream(`https://${new URL(final[0].url).host}/generate_204`);
if (type === StreamType.WebmOpus) { if (type === StreamType.WebmOpus) {
options.seek ??= 0 options.optimization ??= true
if (options.seek >= info.video_details.durationInSec || options.seek < 0) if(options.optimization){
throw new Error(`Seeking beyond limit. [ 0 - ${info.video_details.durationInSec - 1}]`); options.seek ??= 0
return new SeekStream( if (options.seek >= info.video_details.durationInSec || options.seek < 0)
final[0].url, throw new Error(`Seeking beyond limit. [ 0 - ${info.video_details.durationInSec - 1}]`);
info.video_details.durationInSec, return new SeekStream(
final[0].indexRange.end, final[0].url,
Number(final[0].contentLength), info.video_details.durationInSec,
info.video_details.url, final[0].indexRange.end,
options Number(final[0].contentLength),
); info.video_details.url,
} else options
return new Stream( );
final[0].url, }
type, }
info.video_details.durationInSec, return new Stream(
Number(final[0].contentLength), final[0].url,
info.video_details.url, type,
options info.video_details.durationInSec,
); Number(final[0].contentLength),
info.video_details.url,
options
);
} }

View File

@ -100,6 +100,7 @@ async function stream(url: string, options?: StreamOptions): Promise<YouTubeStre
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ] * - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ]
* - `boolean` optimization : Conversion of Webm to Opus [ Defaults to true ]
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> { async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> {
@ -239,6 +240,7 @@ async function stream_from_info(info: InfoData, options?: StreamOptions): Promis
* - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ] * - `number` quality : Quality number. [ 0 = Lowest, 1 = Medium, 2 = Highest ]
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ] * - `number` precache : No of segments of data to store before looping [YouTube Live Stream only]. [ Defaults to 3 ]
* - `boolean` optimization : Conversion of Webm to Opus[ Defaults to true ]
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
async function stream_from_info( async function stream_from_info(