add try catch :p

This commit is contained in:
Ashley 2023-01-12 16:14:31 +00:00
parent f65c0f4d71
commit 866ce9a23e

View file

@ -128,35 +128,39 @@ module.exports = function (app, config, renderTemplate) {
const h = await video.text(); const h = await video.text();
const k = JSON.parse(modules.toJson(h)); const k = JSON.parse(modules.toJson(h));
if (!v) res.redirect("/"); if (!v) res.redirect("/");
if ("Formats" in fetching.video.Player) { try {
//video if ("Formats" in fetching.video.Player) {
const j = fetching.video.Player.Formats.Format, //video
j_ = Array.isArray(j) ? j[j.length - 1] : j; const j = fetching.video.Player.Formats.Format,
let url; j_ = Array.isArray(j) ? j[j.length - 1] : j;
if (j_.URL != undefined) url = j_.URL; let url;
if (j_.URL != undefined) url = j_.URL;
//checks if json exists //checks if json exists
if (json) { if (json) {
//checks if title exists in the json object //checks if title exists in the json object
if ("Title" in json) { if ("Title" in json) {
// json response // json response
const re = { const re = {
main: { main: {
video_id: sha384(json.id), video_id: sha384(json.id),
channel: sha384(json.Channel.Name), channel: sha384(json.Channel.Name),
title: sha384(json.Title), title: sha384(json.Title),
date: sha384(btoa(Date.now()).toString()), date: sha384(btoa(Date.now()).toString()),
}, },
video: { video: {
title: sha384(json.Title), title: sha384(json.Title),
url: sha384(url), url: sha384(url),
}, },
}; };
res.json(re); res.json(re);
}
} }
} }
} catch {
res.json("error in parsing");
} }
}); });