Some improvements

This commit is contained in:
killer069 2022-01-19 09:40:50 +05:30
parent 062a0e7851
commit 54210d1c3f

View File

@ -85,19 +85,18 @@ export async function stream_from_info(
let type: StreamType = let type: StreamType =
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 (options.seek) { if (type === StreamType.WebmOpus) {
if (type === StreamType.WebmOpus) { options.seek ??= 0
if (options.seek >= info.video_details.durationInSec || options.seek <= 0) if (options.seek >= info.video_details.durationInSec || options.seek < 0)
throw new Error(`Seeking beyond limit. [ 1 - ${info.video_details.durationInSec - 1}]`); throw new Error(`Seeking beyond limit. [ 0 - ${info.video_details.durationInSec - 1}]`);
return new SeekStream( return new SeekStream(
final[0].url, final[0].url,
info.video_details.durationInSec, info.video_details.durationInSec,
final[0].indexRange.end, final[0].indexRange.end,
Number(final[0].contentLength), Number(final[0].contentLength),
info.video_details.url, info.video_details.url,
options options
); );
} else throw new Error('Seek is only supported in Webm Opus Files.');
} else } else
return new Stream( return new Stream(
final[0].url, final[0].url,