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.