From 60075f8726853c1fb3e045c241472cc6963be8fc Mon Sep 17 00:00:00 2001 From: Daniel Wykerd Date: Thu, 16 Jun 2022 13:06:10 +0200 Subject: [PATCH] fix: chooseFormat filtering improvements --- lib/parser/youtube/VideoInfo.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/parser/youtube/VideoInfo.js b/lib/parser/youtube/VideoInfo.js index e26a9be8..bfc458c8 100644 --- a/lib/parser/youtube/VideoInfo.js +++ b/lib/parser/youtube/VideoInfo.js @@ -285,9 +285,16 @@ class VideoInfo { }); } - if (is_best) + if (is_best && requires_video) candidates = candidates.filter(format => format.width === best_width); + if (requires_audio && !requires_video) { + const audio_only = candidates.filter(format => !format.has_video); + if (audio_only.length > 0) { + candidates = audio_only; + } + } + if (use_most_efficient) // sort by bitrate (lower is better) candidates.sort((a, b) => a.bitrate - b.bitrate); @@ -303,7 +310,7 @@ class VideoInfo { * @param {object} options - download options. * @param {string} [options.quality] - video quality; 360p, 720p, 1080p, etc... also accepts 'best' and 'bestefficiency'. * @param {string} [options.type] - download type, can be: video, audio or videoandaudio - * @param {string} [options.format] - file format + * @param {string} [options.format] - file format, use 'any' to download any format. * @param {object} [options.range] - download range, indicates which bytes should be downloaded. * @param {number} options.range.start - the beginning of the range. * @param {number} options.range.end - the end of the range.