2023-02-26 22:49:25 +06:00
|
|
|
import { genericUserAgent, maxVideoDuration } from "../../config.js";
|
2023-02-12 13:40:49 +06:00
|
|
|
|
2023-08-20 22:12:09 +06:00
|
|
|
const resolutions = ["2160", "1440", "1080", "720", "480", "360", "240"];
|
2023-02-26 22:49:25 +06:00
|
|
|
|
|
|
|
export default async function(o) {
|
2023-08-20 22:12:09 +06:00
|
|
|
let html, url,
|
|
|
|
quality = o.quality === "max" ? 2160 : o.quality,
|
|
|
|
filename = `vk_${o.userId}_${o.videoId}_`;
|
|
|
|
|
2023-03-08 13:17:33 +06:00
|
|
|
html = await fetch(`https://vk.com/video${o.userId}_${o.videoId}`, {
|
2023-02-12 13:40:49 +06:00
|
|
|
headers: { "user-agent": genericUserAgent }
|
|
|
|
}).then((r) => { return r.text() }).catch(() => { return false });
|
2023-08-20 22:12:09 +06:00
|
|
|
|
2023-02-12 13:40:49 +06:00
|
|
|
if (!html) return { error: 'ErrorCouldntFetch' };
|
|
|
|
if (!html.includes(`{"lang":`)) return { error: 'ErrorEmptyDownload' };
|
|
|
|
|
2023-08-20 22:12:09 +06:00
|
|
|
let js = JSON.parse('{"lang":' + html.split(`{"lang":`)[1].split(']);')[0]);
|
2023-02-12 13:40:49 +06:00
|
|
|
|
2023-02-26 22:49:25 +06:00
|
|
|
if (Number(js.mvData.is_active_live) !== 0) return { error: 'ErrorLiveVideo' };
|
|
|
|
if (js.mvData.duration > maxVideoDuration / 1000) return { error: ['ErrorLengthLimit', maxVideoDuration / 60000] };
|
2023-02-12 13:40:49 +06:00
|
|
|
|
2023-08-20 22:12:09 +06:00
|
|
|
for (let i in resolutions) {
|
|
|
|
if (js.player.params[0][`url${resolutions[i]}`]) {
|
|
|
|
quality = resolutions[i];
|
|
|
|
break
|
|
|
|
}
|
2023-04-29 21:30:59 +06:00
|
|
|
}
|
2023-08-20 22:12:09 +06:00
|
|
|
if (Number(quality) > Number(o.quality)) quality = o.quality;
|
|
|
|
|
|
|
|
url = js.player.params[0][`url${quality}`];
|
|
|
|
filename += `${quality}p.mp4`
|
2023-04-29 21:30:59 +06:00
|
|
|
|
|
|
|
if (url && filename) return {
|
|
|
|
urls: url,
|
|
|
|
filename: filename
|
2023-08-20 22:12:09 +06:00
|
|
|
}
|
2023-02-26 22:49:25 +06:00
|
|
|
return { error: 'ErrorEmptyDownload' }
|
2023-02-12 13:40:49 +06:00
|
|
|
}
|