Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
Added a fallback in case of error
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrn authored Nov 16, 2020
1 parent 0906021 commit 4a9ec78
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 4a9ec78

Please sign in to comment.