From 4700682ccb8fdae753bfe96db6014118c09c89e5 Mon Sep 17 00:00:00 2001 From: wukko Date: Thu, 28 Nov 2024 17:32:10 +0600 Subject: [PATCH] api/vk: refactor quality picking --- api/src/processing/services/vk.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/api/src/processing/services/vk.js b/api/src/processing/services/vk.js index 0ef61c58..33224d69 100644 --- a/api/src/processing/services/vk.js +++ b/api/src/processing/services/vk.js @@ -107,20 +107,16 @@ export default async function ({ ownerId, videoId, accessKey, quality }) { return { error: "content.too_long" }; } - const userQuality = quality === "max" ? 2160 : quality; + const userQuality = quality === "max" ? resolutions[0] : quality; let pickedQuality; - for (let i in resolutions) { - if (video.files[`mp4_${resolutions[i]}`]) { - pickedQuality = resolutions[i]; + for (const resolution of resolutions) { + if (video.files[`mp4_${resolution}`] && +resolution <= +userQuality) { + pickedQuality = resolution; break } } - if (Number(pickedQuality) > Number(userQuality)) { - pickedQuality = userQuality; - } - const url = video.files[`mp4_${pickedQuality}`]; if (!url) return { error: "fetch.fail" };