From 5de7b24dc55fca3eb8fccc6fa30d3c2cd60b8184 Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Thu, 18 May 2023 19:41:21 +0200 Subject: [PATCH] perf(toDash): Speed up format filtering (#405) --- src/utils/FormatUtils.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/utils/FormatUtils.ts b/src/utils/FormatUtils.ts index a81ef42e..75c63950 100644 --- a/src/utils/FormatUtils.ts +++ b/src/utils/FormatUtils.ts @@ -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');