perf(toDash): Speed up format filtering (#405)

This commit is contained in:
absidue
2023-05-18 19:41:21 +02:00
committed by GitHub
parent 01fd1ee72a
commit 5de7b24dc5

View File

@@ -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');