From 4a9ec78925d927145b660e65498eccad265633c5 Mon Sep 17 00:00:00 2001 From: Andrea Barzaghi <54246837+dbrn@users.noreply.github.com> Date: Mon, 16 Nov 2020 22:57:30 +0100 Subject: [PATCH] Added a fallback in case of error --- lib/util.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/util.js b/lib/util.js index 2fdd519..3aa9bc5 100644 --- a/lib/util.js +++ b/lib/util.js @@ -91,17 +91,21 @@ exports.getVideoContainers = (body) => { }; exports.buildVideoObject = (videoObject) => { - return { - id: videoObject.playlistVideoRenderer.videoId, - url: `https://www.youtube.com/watch?v=${videoObject.playlistVideoRenderer.videoId}`, - title: removeHtml(videoObject.playlistVideoRenderer.title.runs[0].text), - thumbnail: videoObject.playlistVideoRenderer.thumbnail.thumbnails[0].url, - duration: videoObject.playlistVideoRenderer.lengthText.simpleText, - author: { - name: videoObject.playlistVideoRenderer.shortBylineText.runs[0].text, - ref: `https://www.youtube.com/${videoObject.playlistVideoRenderer.shortBylineText.runs[0].navigationEndpoint.commandMetadata.url}`, - }, - }; + if (typeof videoObject.playlistVideoRenderer !== "undefined") { + return { + id: videoObject.playlistVideoRenderer.videoId, + url: `https://www.youtube.com/watch?v=${videoObject.playlistVideoRenderer.videoId}`, + title: removeHtml(videoObject.playlistVideoRenderer.title.runs[0].text), + thumbnail: videoObject.playlistVideoRenderer.thumbnail.thumbnails[0].url, + duration: videoObject.playlistVideoRenderer.lengthText.simpleText, + author: { + name: videoObject.playlistVideoRenderer.shortBylineText.runs[0].text, + ref: `https://www.youtube.com/${videoObject.playlistVideoRenderer.shortBylineText.runs[0].navigationEndpoint.commandMetadata.url}`, + }, + }; + } else { + return {}; + } }; // Taken from https://github.com/fent/node-ytdl-core/