api/vk: refactor quality picking

This commit is contained in:
wukko 2024-11-28 17:32:10 +06:00
parent f696335278
commit 4700682ccb
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2

View file

@ -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" };