From 25cfecbbf94a3d32047c0c71ccaaf135de5560be Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 13 Feb 2022 05:04:24 +0300 Subject: [PATCH] Update update.js --- scripts/commands/database/update.js | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/commands/database/update.js b/scripts/commands/database/update.js index 55d768beb..07ae6a717 100644 --- a/scripts/commands/database/update.js +++ b/scripts/commands/database/update.js @@ -133,20 +133,16 @@ function findOrigin(requests = [], origins = {}) { } function parseStreams(streams) { - const data = streams - .filter(s => s.codec_type === 'video') - .reduce( - (acc, curr) => { - if (curr.height > acc.height) { - const bitrate = curr.tags.variant_bitrate ? parseInt(curr.tags.variant_bitrate) : 0 - return { width: curr.width, height: curr.height, bitrate } - } - return acc - }, - { width: 0, height: 0, bitrate: 0 } - ) + streams = streams.filter(s => s.codec_type === 'video') + streams = _.orderBy(streams, ['height', 'bitrate'], ['desc', 'desc']) - return data + const data = _.head(streams) + if (data) { + const bitrate = data.tags.variant_bitrate ? parseInt(data.tags.variant_bitrate) : 0 + return { width: data.width, height: data.height, bitrate } + } + + return {} } function parseError(error) {