Skip to content

Commit

Permalink
fix(FormatUtils): itag matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier authored Feb 2, 2025
1 parent 1c1577e commit 5f78fd1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/utils/FormatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ export function chooseFormat(options: FormatOptions, streaming_data?: IStreaming
...(streaming_data.formats || []),
...(streaming_data.adaptive_formats || [])
];

if (options.itag) {
const candidates = formats.filter((format) => format.itag === options.itag);
if (!candidates.length)
throw new InnertubeError('No matching formats found', { options });

return candidates[0];
}

const requires_audio = options.type ? options.type.includes('audio') : true;
const requires_video = options.type ? options.type.includes('video') : true;
Expand All @@ -155,8 +163,6 @@ export function chooseFormat(options: FormatOptions, streaming_data?: IStreaming
const use_most_efficient = quality !== 'best';

let candidates = formats.filter((format) => {
if (options.itag && format.itag !== options.itag)
return false;
if (requires_audio && !format.has_audio)
return false;
if (requires_video && !format.has_video)
Expand Down

0 comments on commit 5f78fd1

Please sign in to comment.