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

Adjust parsing of channel page #113

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ class YoutubeGrabberHelper {
const videoTab = YoutubeGrabberHelper.findTab(channelPageDataResponse.contents.twoColumnBrowseResultsRenderer.tabs)

let channelVideoData
if (videoTab && 'sectionListRenderer' in videoTab.tabRenderer.content) {
channelVideoData = videoTab.tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
if (videoTab && 'richGridRenderer' in videoTab.tabRenderer.content) {
channelVideoData = { items: videoTab.tabRenderer.content.richGridRenderer.contents }
} else if (videoTab && 'sectionListRenderer' in videoTab.tabRenderer.content) {
const contents = videoTab.tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0]
if ('reelShelfRenderer' in contents) {
channelVideoData = contents.reelShelfRenderer
}
}
if (typeof (channelVideoData) === 'undefined') {
// Channel has no videos
Expand Down Expand Up @@ -181,8 +186,15 @@ class YoutubeGrabberHelper {
let lengthSeconds = 0
let durationText
let publishedText = ''

if (typeof (obj.gridVideoRenderer) === 'undefined' && typeof (obj.videoRenderer) !== 'undefined') {
if (typeof (obj.richItemRenderer) !== 'undefined') {
video = obj.richItemRenderer.content.videoRenderer
video.lengthSeconds = video.lengthText.simpleText.split(':').reduce((acc, time) => (60 * acc) + +time)
video.title.simpleText = video.title.runs.at(0)
} else if (typeof (obj.reelItemRenderer) !== 'undefined') {
video = obj.reelItemRenderer
video.title = video.headline
video.publishedTimeText = { simpleText: '' }
} else if (typeof (obj.gridVideoRenderer) === 'undefined' && typeof (obj.videoRenderer) !== 'undefined') {
video = obj.videoRenderer
} else if (typeof (obj.gridVideoRenderer) !== 'undefined') {
video = obj.gridVideoRenderer
Expand All @@ -192,7 +204,7 @@ class YoutubeGrabberHelper {

let title = video.title.simpleText
let statusRenderer
if (!('channelVideoPlayerRenderer' in obj)) {
if (!('channelVideoPlayerRenderer' in obj) && !('reelItemRenderer' in obj)) {
statusRenderer = video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer
}

Expand Down Expand Up @@ -228,7 +240,7 @@ class YoutubeGrabberHelper {

publishedText = video.publishedTimeText.simpleText

if (!('channelVideoPlayerRenderer' in obj) && typeof (video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer) !== 'undefined') {
if (!('channelVideoPlayerRenderer' in obj) && !('reelItemRenderer' in obj) && typeof (video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer) !== 'undefined') {
durationText = video.thumbnailOverlays[0].thumbnailOverlayTimeStatusRenderer.text.simpleText
const durationSplit = durationText.split(':')

Expand Down Expand Up @@ -309,7 +321,7 @@ class YoutubeGrabberHelper {
const communityTab = YoutubeGrabberHelper.findTab(contentDataJSON.contents.twoColumnBrowseResultsRenderer.tabs)

if (communityTab) {
contentDataJSON = contentDataJSON.contents.twoColumnBrowseResultsRenderer.tabs[3].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer
contentDataJSON = communityTab.tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer
if ('continuationItemRenderer' in contentDataJSON.contents[contentDataJSON.contents.length - 1]) {
return { items: this.createCommunityPostArray(contentDataJSON.contents), continuation: contentDataJSON.contents[contentDataJSON.contents.length - 1].continuationItemRenderer.continuationEndpoint.continuationCommand.token, innerTubeApi: innertubeAPIkey, channelIdType: channelIdType }
}
Expand Down