Add logic to catch empty formats

This commit is contained in:
Juan Carlos Ramirez 2025-01-20 17:44:07 -06:00
parent 35855dd164
commit 0db43cee32

View file

@ -524,6 +524,10 @@ export default class {
format = formats.find(filter); format = formats.find(filter);
const nextBestFormat = (formats: ytdl.videoFormat[]): ytdl.videoFormat | undefined => { const nextBestFormat = (formats: ytdl.videoFormat[]): ytdl.videoFormat | undefined => {
if (formats.length < 1) {
return undefined;
}
if (formats[0].isLive) { if (formats[0].isLive) {
formats = formats.sort((a, b) => (b as unknown as {audioBitrate: number}).audioBitrate - (a as unknown as {audioBitrate: number}).audioBitrate); // Bad typings formats = formats.sort((a, b) => (b as unknown as {audioBitrate: number}).audioBitrate - (a as unknown as {audioBitrate: number}).audioBitrate); // Bad typings