Skip to content

Commit

Permalink
perf(toDash): Speed up format filtering (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored May 18, 2023
1 parent 01fd1ee commit 5de7b24
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/utils/FormatUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,22 +249,14 @@ class FormatUtils {
if (!streaming_data)
throw new InnertubeError('Streaming data not available');

let filtered_streaming_data;
let adaptive_formats;

if (format_filter) {
filtered_streaming_data = {
formats: streaming_data.formats.filter((fmt: Format) => !(format_filter(fmt))),
adaptive_formats: streaming_data.adaptive_formats.filter((fmt: Format) => !(format_filter(fmt))),
expires: streaming_data.expires,
dash_manifest_url: streaming_data.dash_manifest_url,
hls_manifest_url: streaming_data.hls_manifest_url
};
adaptive_formats = streaming_data.adaptive_formats.filter((fmt: Format) => !(format_filter(fmt)));
} else {
filtered_streaming_data = streaming_data;
adaptive_formats = streaming_data.adaptive_formats;
}

const { adaptive_formats } = filtered_streaming_data;

if (!adaptive_formats.length)
throw new InnertubeError('No adaptive formats found');

Expand Down

0 comments on commit 5de7b24

Please sign in to comment.