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

Commit

Permalink
Adjust parsing of channel page continuation (#115)
Browse files Browse the repository at this point in the history
* Fix title assignment

* Map `channelId` and `channeName` when metadata is not present

* Linted
  • Loading branch information
MarmadileManteater authored Nov 2, 2022
1 parent b23e6b9 commit 25681ca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class YoutubeGrabberHelper {
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)
video.title.simpleText = video.title.runs.at(0).text
} else if (typeof (obj.reelItemRenderer) !== 'undefined') {
video = obj.reelItemRenderer
video.title = video.headline
Expand Down
23 changes: 17 additions & 6 deletions app/youtube-grabber.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,24 @@ class YoutubeGrabber {
nextContinuation = continuationItem[0].continuationItemRenderer.continuationEndpoint.continuationCommand.token
}

const channelMetaData = channelPageResponse.data.metadata.channelMetadataRenderer
const channelName = channelMetaData.title
const channelId = channelMetaData.externalId
const channelMetaData = channelPageResponse.data?.metadata?.channelMetadataRenderer
let channelInfo = {}
if (channelMetaData) {
const channelName = channelMetaData.title
const channelId = channelMetaData.externalId

channelInfo = {
channelId,
channelName
}
} else {
const firstVideoTitle = continuationData[0].richItemRenderer.content.videoRenderer.title
const firstPublishTimeText = continuationData[0].richItemRenderer.content.videoRenderer.publishedTimeText

const channelInfo = {
channelId: channelId,
channelName: channelName
channelInfo = {
channelId: channelPageResponse.data.responseContext.serviceTrackingParams.find((service) => service.service === 'GOOGLE_HELP').params[0].value,
channelName: new RegExp(`${firstVideoTitle.runs[0].text} by (.*?) ${firstPublishTimeText.simpleText}`, 'g').exec(firstVideoTitle.accessibility.accessibilityData.label)[1]
}
}

const nextVideos = continuationData.filter((item) => {
Expand Down

0 comments on commit 25681ca

Please sign in to comment.