proritise format with smallest size

This commit is contained in:
localhost 2025-08-18 12:35:17 +03:00
parent e448db5cd0
commit 465ff60d76
1 changed files with 14 additions and 1 deletions

View File

@ -174,7 +174,20 @@ export async function createSabrStream(
} }
}); });
const { videoStream, audioStream, selectedFormats } = await serverAbrStream.start(options); // thank you to @olokelo for this suggestion - my favourite damn codec nerd
const lowestStorageVideo = sabrFormats
.filter((format) => !!format.qualityLabel?.toLowerCase().includes(options.videoQuality?.toLowerCase() || ''))
.sort((a, b) => (a.contentLength || 0) - (b.contentLength || 0))?.[0]
const lowestStorageAudio = sabrFormats
.filter((format) => !!format.audioQuality?.toLowerCase().includes(options.audioQuality?.toLowerCase() || ''))
.sort((a, b) => (a.contentLength || 0) - (b.contentLength || 0))?.[0]
const lowestOptions = {
videoFormat: lowestStorageVideo?.itag,
audioFormat: lowestStorageAudio?.itag
}
const { videoStream, audioStream, selectedFormats } // if we found the lowest storage, use those, otherwise let lib do its own magic
= await serverAbrStream.start((lowestOptions.videoFormat && lowestOptions.audioFormat) ? lowestOptions : options);
return { return {
innertube, innertube,