From a7c3d42b7859d0de02fb71d1e2f0a56d6b9ded5c Mon Sep 17 00:00:00 2001 From: Ashley Date: Thu, 12 Jan 2023 16:14:31 +0000 Subject: [PATCH] add try catch :p --- src/libpoketube/init/pages-video.js | 52 ++++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/src/libpoketube/init/pages-video.js b/src/libpoketube/init/pages-video.js index 31c4e89c..0899eb60 100644 --- a/src/libpoketube/init/pages-video.js +++ b/src/libpoketube/init/pages-video.js @@ -128,35 +128,39 @@ module.exports = function (app, config, renderTemplate) { const h = await video.text(); const k = JSON.parse(modules.toJson(h)); if (!v) res.redirect("/"); - if ("Formats" in fetching.video.Player) { - //video - const j = fetching.video.Player.Formats.Format, - j_ = Array.isArray(j) ? j[j.length - 1] : j; - let url; - if (j_.URL != undefined) url = j_.URL; + try { + if ("Formats" in fetching.video.Player) { + //video + const j = fetching.video.Player.Formats.Format, + j_ = Array.isArray(j) ? j[j.length - 1] : j; + let url; + if (j_.URL != undefined) url = j_.URL; - //checks if json exists - if (json) { - //checks if title exists in the json object + //checks if json exists + if (json) { + //checks if title exists in the json object - if ("Title" in json) { - // json response - const re = { - main: { - video_id: sha384(json.id), - channel: sha384(json.Channel.Name), - title: sha384(json.Title), - date: sha384(btoa(Date.now()).toString()), - }, - video: { - title: sha384(json.Title), - url: sha384(url), - }, - }; + if ("Title" in json) { + // json response + const re = { + main: { + video_id: sha384(json.id), + channel: sha384(json.Channel.Name), + title: sha384(json.Title), + date: sha384(btoa(Date.now()).toString()), + }, + video: { + title: sha384(json.Title), + url: sha384(url), + }, + }; - res.json(re); + res.json(re); + } } } + } catch { + res.json("error in parsing"); } });