Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #34 from GilgusMaximus/master
Browse files Browse the repository at this point in the history
Added author field, fixed missing parts of the post's text.
  • Loading branch information
GilgusMaximus authored May 22, 2021
2 parents 1f9db53 + 98d4d68 commit fa7b305
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 29 additions & 3 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit fa7b305

Please sign in to comment.