mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-28 02:26:10 +00:00
api/vk: refactor quality picking
This commit is contained in:
parent
f696335278
commit
4700682ccb
|
@ -107,20 +107,16 @@ export default async function ({ ownerId, videoId, accessKey, quality }) {
|
||||||
return { error: "content.too_long" };
|
return { error: "content.too_long" };
|
||||||
}
|
}
|
||||||
|
|
||||||
const userQuality = quality === "max" ? 2160 : quality;
|
const userQuality = quality === "max" ? resolutions[0] : quality;
|
||||||
let pickedQuality;
|
let pickedQuality;
|
||||||
|
|
||||||
for (let i in resolutions) {
|
for (const resolution of resolutions) {
|
||||||
if (video.files[`mp4_${resolutions[i]}`]) {
|
if (video.files[`mp4_${resolution}`] && +resolution <= +userQuality) {
|
||||||
pickedQuality = resolutions[i];
|
pickedQuality = resolution;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number(pickedQuality) > Number(userQuality)) {
|
|
||||||
pickedQuality = userQuality;
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = video.files[`mp4_${pickedQuality}`];
|
const url = video.files[`mp4_${pickedQuality}`];
|
||||||
|
|
||||||
if (!url) return { error: "fetch.fail" };
|
if (!url) return { error: "fetch.fail" };
|
||||||
|
|
Loading…
Reference in a new issue