diff --git a/README.md b/README.md index a921cf4..49f9018 100644 --- a/README.md +++ b/README.md @@ -278,7 +278,8 @@ The objects in the array of community posts all follow a basic structure but var ```javascript postData = { postText: String, - postId: String, + postId: String, + author: String, authorThumbnails: Array[Object], // Array of objects with links to images publishedText: String, voteCount: String, diff --git a/app/helper.js b/app/helper.js index 7af750e..7b32424 100644 --- a/app/helper.js +++ b/app/helper.js @@ -209,19 +209,30 @@ class YoutubeGrabberHelper { // we do not want to access the continuation data like a normal post, but instead later return } - + if ('sharedPostRenderer' in post.backstagePostThreadRenderer.post) { + // this are special and rare posts, we only care about the text no content + const postData = this.parseSharedPost(post) + postsArray.push(postData) + return + } // Default structure of a post + // comment count not available on shared posts const postData = { - postText: ('runs' in post.backstagePostThreadRenderer.post.backstagePostRenderer.contentText) ? post.backstagePostThreadRenderer.post.backstagePostRenderer.contentText.runs[0].text : null, + postText: '', postId: post.backstagePostThreadRenderer.post.backstagePostRenderer.postId, + author: post.backstagePostThreadRenderer.post.backstagePostRenderer.authorText.runs[0].text, authorThumbnails: post.backstagePostThreadRenderer.post.backstagePostRenderer.authorThumbnail.thumbnails, publishedText: post.backstagePostThreadRenderer.post.backstagePostRenderer.publishedTimeText.runs[0].text, voteCount: post.backstagePostThreadRenderer.post.backstagePostRenderer.voteCount.simpleText, postContent: null, commentCount: ('text' in post.backstagePostThreadRenderer.post.backstagePostRenderer.actionButtons.commentActionButtonsRenderer.replyButton.buttonRenderer) ? post.backstagePostThreadRenderer.post.backstagePostRenderer.actionButtons.commentActionButtonsRenderer.replyButton.buttonRenderer.text.simpleText : '0' } + if ('runs' in post.backstagePostThreadRenderer.post.backstagePostRenderer.contentText) { + // eslint-disable-next-line no-return-assign + post.backstagePostThreadRenderer.post.backstagePostRenderer.contentText.runs.forEach((element, index) => postData.postText += (index !== 0) ? ' ' + element.text : element.text) + } - // if this exists, then the post contains more data than only text + // if this exists, then the post contains more data than only text - Assumption: sharedPostRenderer only has text. Only occurred once so far if ('backstageAttachment' in post.backstagePostThreadRenderer.post.backstagePostRenderer) { if ('backstageImageRenderer' in post.backstagePostThreadRenderer.post.backstagePostRenderer.backstageAttachment) { // post with an image @@ -287,6 +298,21 @@ class YoutubeGrabberHelper { return postsArray } + parseSharedPost(post) { + const postData = { + postText: '', + postId: post.backstagePostThreadRenderer.post.sharedPostRenderer.postId, + author: post.backstagePostThreadRenderer.post.sharedPostRenderer.displayName.runs[0].text, + authorThumbnails: post.backstagePostThreadRenderer.post.sharedPostRenderer.thumbnail.thumbnails, + publishedText: post.backstagePostThreadRenderer.post.sharedPostRenderer.publishedTimeText.runs[0].text, + voteCount: post.backstagePostThreadRenderer.post.sharedPostRenderer.originalPost.backstagePostRenderer.voteCount.simpleText, + postContent: null, + commentCount: ('text' in post.backstagePostThreadRenderer.post.sharedPostRenderer.originalPost.backstagePostRenderer.actionButtons.commentActionButtonsRenderer.replyButton.buttonRenderer) ? post.backstagePostThreadRenderer.post.sharedPostRenderer.originalPost.backstagePostRenderer.actionButtons.commentActionButtonsRenderer.replyButton.buttonRenderer.text.simpleText : '0', + } + post.backstagePostThreadRenderer.post.sharedPostRenderer.content.runs.forEach((element, index) => postData.postText += (index !== 0) ? ' ' + element.text : element.text) + return post + } + parsePlaylist(obj, channelInfo) { if (typeof (obj.gridShowRenderer) !== 'undefined') { return diff --git a/package.json b/package.json index 4f54a34..d69cb02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yt-channel-info", - "version": "2.1.1", + "version": "2.2.0", "description": "Grab YouTube channel information without any official API", "main": "index.js", "scripts": {