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

Adjust regex to be more resilient #116

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
19 changes: 13 additions & 6 deletions app/youtube-grabber.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,19 @@ class YoutubeGrabber {
channelName
}
} else {
const firstVideoTitle = continuationData[0].richItemRenderer.content.videoRenderer.title
const firstPublishTimeText = continuationData[0].richItemRenderer.content.videoRenderer.publishedTimeText

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]
let i = 0
// Look through every video until you can successfully find the channel metadata
while (channelInfo.channelName === undefined && i < continuationData.length - 1) {
const videoTitle = continuationData[i].richItemRenderer.content.videoRenderer.title
const publishTimeText = continuationData[i].richItemRenderer.content.videoRenderer.publishedTimeText
channelInfo = {
channelId: channelPageResponse.data.responseContext.serviceTrackingParams.find((service) => service.service === 'GOOGLE_HELP').params[0].value
}
const channelNameRegex = new RegExp(`${videoTitle.runs[0].text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')} by (.*?) ${publishTimeText.simpleText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`, 'g').exec(videoTitle.accessibility.accessibilityData.label)
if (channelNameRegex !== null && channelNameRegex.length > 1) {
channelInfo.channelName = channelNameRegex[1]
}
i++
}
}

Expand Down