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

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer committed Sep 14, 2022
1 parent ac06594 commit 9d5f865
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/fetchers/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PlaylistFetcher {
let playlistData
const playlistTab = YoutubeGrabberHelper.findTab(channelPageDataResponse.contents.twoColumnBrowseResultsRenderer.tabs)

if (playlistTab !== undefined) {
if (playlistTab && 'sectionListRenderer' in playlistTab.tabRenderer.content) {
const tabRenderer = playlistTab.tabRenderer
playlistData = tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
}
Expand Down
4 changes: 2 additions & 2 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class YoutubeGrabberHelper {
const videoTab = YoutubeGrabberHelper.findTab(channelPageDataResponse.contents.twoColumnBrowseResultsRenderer.tabs)

let channelVideoData
if (videoTab !== undefined) {
channelVideoData = channelPageDataResponse.contents.twoColumnBrowseResultsRenderer.tabs[1].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
if (videoTab && 'sectionListRenderer' in videoTab.tabRenderer.content) {
channelVideoData = videoTab.tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
}
if (typeof (channelVideoData) === 'undefined') {
// Channel has no videos
Expand Down
34 changes: 16 additions & 18 deletions app/youtube-grabber.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,20 @@ class YoutubeGrabber {
}
}

const channelMetaData = channelPageDataResponse.metadata.channelMetadataRenderer
const channelHeaderData = channelPageDataResponse.header.c4TabbedHeaderRenderer
const channelMetaData = channelPageDataResponse?.metadata?.channelMetadataRenderer
let channelHeaderData = channelPageDataResponse.header.c4TabbedHeaderRenderer
if (!channelHeaderData) {
channelHeaderData = channelPageDataResponse.header.carouselHeaderRenderer.contents[1].topicChannelDetailsRenderer
// = topicChannelDetailsRenderer
}
const headerTabs = channelPageDataResponse.contents.twoColumnBrowseResultsRenderer.tabs
const channelTabs = headerTabs
.filter(tab => tab.tabRenderer !== undefined && tab.tabRenderer !== null)
.map(tab => tab.tabRenderer.title)

const channelsTab = YoutubeGrabberHelper.findTab(headerTabs)
let featuredChannels = {}
if (channelsTab !== undefined) {
if (channelsTab && 'sectionListRenderer' in channelsTab.tabRenderer.content) {
featuredChannels = channelsTab.tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0]
}
let relatedChannels = []
Expand Down Expand Up @@ -132,23 +136,22 @@ class YoutubeGrabber {
isOfficialArtist = channelHeaderData.badges.some((badge) => badge.metadataBadgeRenderer.style === 'BADGE_STYLE_TYPE_VERIFIED_ARTIST')
}

const tags = channelPageDataResponse.microformat.microformatDataRenderer.tags || null

const tags = channelPageDataResponse?.microformat?.microformatDataRenderer?.tags || null
const channelInfo = {
author: channelMetaData.title,
authorId: channelMetaData.externalId,
authorUrl: channelMetaData.vanityChannelUrl,
author: channelMetaData?.title ?? channelHeaderData.title.simpleText,
authorId: channelMetaData?.externalId ?? channelHeaderData.navigationEndpoint.browseEndpoint.browseId,
authorUrl: channelMetaData?.vanityChannelUrl ?? channelHeaderData.navigationEndpoint.commandMetadata.webCommandMetadata.url,
authorBanners: bannerThumbnails,
authorThumbnails: channelHeaderData.avatar.thumbnails,
subscriberText: subscriberText,
subscriberCount: subscriberCount,
description: channelMetaData.description,
isFamilyFriendly: channelMetaData.isFamilySafe,
description: channelMetaData?.description ?? '',
isFamilyFriendly: channelMetaData?.isFamilySafe ?? false,
relatedChannels: {
items: relatedChannels,
continuation: relatedChannelsContinuation
},
allowedRegions: channelMetaData.availableCountryCodes,
allowedRegions: channelMetaData?.availableCountryCodes ?? [],
isVerified: isVerified,
isOfficialArtist: isOfficialArtist,
tags: tags,
Expand Down Expand Up @@ -495,11 +498,7 @@ class YoutubeGrabber {
}
}

static async getChannelHome(payload) {
const channelId = payload.channelId
const channelIdType = payload.channelIdType ?? 0
const httpAgent = payload.httpAgent ?? null

static async getChannelHome({ channelId, channelIdType = 0, httpAgent = null }) {
const ytGrabHelp = YoutubeGrabberHelper.create(httpAgent)
const decideResponse = await ytGrabHelp.decideUrlRequestType(channelId, 'home?flow=grid&view=0&pbj=1', channelIdType)
const channelPageResponse = decideResponse.response
Expand Down Expand Up @@ -531,10 +530,9 @@ class YoutubeGrabber {
}

const homeTab = YoutubeGrabberHelper.findTab(headerTabs)

let featuredVideo = null
let homeItems = []
if (homeTab !== undefined) {
if ('sectionListRenderer' in homeTab.tabRenderer.content) {
homeItems = homeTab.tabRenderer.content.sectionListRenderer.contents.filter(x => {
if ('shelfRenderer' in x.itemSectionRenderer.contents[0]) {
return true
Expand Down

0 comments on commit 9d5f865

Please sign in to comment.