From 35fc9f9b7f633f0c05db72fbce1f379607fcc890 Mon Sep 17 00:00:00 2001 From: Ashley Date: Fri, 9 Dec 2022 19:03:28 +0000 Subject: [PATCH] fix dislikes --- src/libpoketube/libpoketube-fetcher.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/libpoketube/libpoketube-fetcher.js b/src/libpoketube/libpoketube-fetcher.js index 7bda8c13..2c1e65e2 100644 --- a/src/libpoketube/libpoketube-fetcher.js +++ b/src/libpoketube/libpoketube-fetcher.js @@ -24,13 +24,20 @@ var dislike_api = `https://returnyoutubedislikeapi.com/votes?videoId=`; var new_api_url = `https://tube.kuylar.dev/api/player`; module.exports = async function (video_id) { + +function getJson(str) { + try { + return JSON.parse(str); + } catch { + return null; + } +} + const dislike = await fetch(`${dislike_api}${video_id}`).then((res) => - res.json() + getJson(res) ); - const dislikes = dislike.dislikes || "none"; - - const headers = {}; + const headers = {}; /* * Parses and fetches an xml */