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

Commit

Permalink
Author id for posts & test suite update (#84)
Browse files Browse the repository at this point in the history
* Added upcoming video test

* Added missing author id to videos and playlist elements

* Redid package-lock

* Update test/channelVideos.test.js

Co-authored-by: PikachuEXE <pikachuexe@gmail.com>

* Revert "Redid package-lock"

This reverts commit 3d01379.

* fix lint, remove yarn.lock

Co-authored-by: PikachuEXE <pikachuexe@gmail.com>
Co-authored-by: onion chunky <78101139+ChunkyProgrammer@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 24, 2022
1 parent 048e741 commit 1edd78f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,14 @@ class YoutubeGrabberHelper {
postText: '',
postId: post.backstagePostThreadRenderer.post.backstagePostRenderer.postId,
author: post.backstagePostThreadRenderer.post.backstagePostRenderer.authorText.runs[0].text,
authorId: this.extractChannelId(post.backstagePostThreadRenderer.post.backstagePostRenderer.authorEndpoint),
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) => {
Expand All @@ -350,6 +352,7 @@ class YoutubeGrabberHelper {
} else if ('videoRenderer' in post.backstagePostThreadRenderer.post.backstagePostRenderer.backstageAttachment) {
// post with a video
const videoRenderer = post.backstagePostThreadRenderer.post.backstagePostRenderer.backstageAttachment.videoRenderer

postData.postContent = {
type: 'video',
content: {
Expand All @@ -361,6 +364,7 @@ class YoutubeGrabberHelper {
viewCountText: videoRenderer.viewCountText.simpleText,
badges: { verified: false, officialArtist: false },
author: videoRenderer.ownerText.runs[0].text,
authorId: this.extractChannelId(videoRenderer.ownerText.runs[0].navigationEndpoint),
thumbnails: videoRenderer.thumbnail.thumbnails
}
}
Expand All @@ -385,6 +389,7 @@ class YoutubeGrabberHelper {
videoCountText: playlistRenderer.videoCountText.runs[0],
ownerBadges: playlistRenderer.ownerBadges,
author: playlistRenderer.longBylineText.runs[0].text,
authorId: this.extractChannelId(playlistRenderer.longBylineText.runs[0].navigationEndpoint), // this might fail, no channel with a playlist posted was found
thumbnails: playlistRenderer.thumbnails
}
}
Expand Down Expand Up @@ -414,6 +419,11 @@ class YoutubeGrabberHelper {
return postsArray
}

extractChannelId(browseEndPoint) {
const channelLinkSplit = browseEndPoint.commandMetadata.webCommandMetadata.url.split('/')
return channelLinkSplit[channelLinkSplit.length - 1]
}

extractLinks(text) {
if ('urlEndpoint' in text.navigationEndpoint) {
const linkText = text.navigationEndpoint.urlEndpoint.url
Expand Down
9 changes: 9 additions & 0 deletions test/channelVideos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,13 @@ describe('Getting channel videos', () => {
expect(data.items.length).toBe(0)
})
})

test('Upcoming video', () => {
// https://www.youtube.com/channel/UCUKPG1-r4WFyxpyhIuCs86Q
// This channel has a video premiering in 2024/3/31
const parameters = { channelId: 'UCUKPG1-r4WFyxpyhIuCs86Q', channelIdType: 1 }
return ytch.getChannelVideos(parameters).then((data) => {
expect(data.items.length).toBeGreaterThan(0)
})
})
})

0 comments on commit 1edd78f

Please sign in to comment.