mirror of
https://github.com/imputnet/cobalt.git
synced 2024-12-26 17:46:06 +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" };
|
||||
}
|
||||
|
||||
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" };
|
||||
|
|
Loading…
Reference in a new issue