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

Commit

Permalink
change data[1] to data (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunkyProgrammer authored Apr 6, 2022
1 parent 16a9836 commit 81ba310
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/fetchers/playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlaylistFetcher {
}

static async parseChannelPlaylistResponse (response, channelIdType, httpAgent = null) {
const channelMetaData = response.data[1].response.metadata.channelMetadataRenderer
const channelMetaData = response.data.response.metadata.channelMetadataRenderer
const channelName = channelMetaData.title
const channelId = channelMetaData.externalId
const ytGrabHelp = helper.create(httpAgent)
Expand All @@ -36,7 +36,7 @@ class PlaylistFetcher {
channelUrl: `https://www.youtube.com/channel/${channelId}`
}

const playlistData = response.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs[2].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
const playlistData = response.data.response.contents.twoColumnBrowseResultsRenderer.tabs[2].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer

if (typeof (playlistData) === 'undefined') {
return {
Expand Down
8 changes: 4 additions & 4 deletions app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ class YoutubeGrabberHelper {
}

async parseChannelVideoResponse(response, channelId, channelIdType) {
if (typeof (response.data[1].response.alerts) !== 'undefined') {
if (typeof (response.data.response.alerts) !== 'undefined') {
return {
alertMessage: response.data[1].response.alerts[0].alertRenderer.text.simpleText
alertMessage: response.data.response.alerts[0].alertRenderer.text.simpleText
}
}

const channelMetaData = response.data[1].response.metadata.channelMetadataRenderer
const channelMetaData = response.data.response.metadata.channelMetadataRenderer
const channelName = channelMetaData.title
const channelVideoData = response.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs[1].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer
const channelVideoData = response.data.response.contents.twoColumnBrowseResultsRenderer.tabs[1].tabRenderer.content.sectionListRenderer.contents[0].itemSectionRenderer.contents[0].gridRenderer

if (typeof (channelVideoData) === 'undefined') {
// Channel has no videos
Expand Down
27 changes: 13 additions & 14 deletions app/youtube-grabber.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class YoutubeGrabber {
const ytGrabHelp = YoutubeGrabberHelper.create(httpAgent)
const decideResponse = await ytGrabHelp.decideUrlRequestType(channelId, 'channels?flow=grid&view=0&pbj=1', channelIdType)
const channelPageResponse = decideResponse.response

const headerLinks = channelPageResponse.data[1].response.header.c4TabbedHeaderRenderer.headerLinks
const headerLinks = channelPageResponse.data.response.header.c4TabbedHeaderRenderer.headerLinks
const links = {
primaryLinks: [],
secondaryLinks: []
Expand All @@ -48,15 +47,15 @@ class YoutubeGrabber {
})
}
}
if (typeof (channelPageResponse.data[1].response.alerts) !== 'undefined') {
if (typeof (channelPageResponse.data.response.alerts) !== 'undefined') {
return {
alertMessage: channelPageResponse.data[1].response.alerts[0].alertRenderer.text.simpleText
alertMessage: channelPageResponse.data.response.alerts[0].alertRenderer.text.simpleText
}
}

const channelMetaData = channelPageResponse.data[1].response.metadata.channelMetadataRenderer
const channelHeaderData = channelPageResponse.data[1].response.header.c4TabbedHeaderRenderer
const headerTabs = channelPageResponse.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs
const channelMetaData = channelPageResponse.data.response.metadata.channelMetadataRenderer
const channelHeaderData = channelPageResponse.data.response.header.c4TabbedHeaderRenderer
const headerTabs = channelPageResponse.data.response.contents.twoColumnBrowseResultsRenderer.tabs

const channelsTab = headerTabs.filter((data) => {
if (typeof data.tabRenderer !== 'undefined') {
Expand Down Expand Up @@ -136,7 +135,7 @@ class YoutubeGrabber {
isOfficialArtist = channelHeaderData.badges.some((badge) => badge.metadataBadgeRenderer.style === 'BADGE_STYLE_TYPE_VERIFIED_ARTIST')
}

const tags = channelPageResponse.data[1].response.microformat.microformatDataRenderer.tags || null
const tags = channelPageResponse.data.response.microformat.microformatDataRenderer.tags || null

const channelInfo = {
author: channelMetaData.title,
Expand Down Expand Up @@ -390,7 +389,7 @@ class YoutubeGrabber {
const decideResponse = await ytGrabHelp.decideUrlRequestType(channelId, `search?${urlParams}`, channelIdType)
const channelPageResponse = decideResponse.response

const channelMetaData = channelPageResponse.data[1].response.metadata.channelMetadataRenderer
const channelMetaData = channelPageResponse.data.response.metadata.channelMetadataRenderer
const channelName = channelMetaData.title

const channelInfo = {
Expand All @@ -399,13 +398,13 @@ class YoutubeGrabber {
channelUrl: `https://www.youtube.com/channel/${channelId}`
}

const searchTab = channelPageResponse.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs.findIndex((tab) => {
const searchTab = channelPageResponse.data.response.contents.twoColumnBrowseResultsRenderer.tabs.findIndex((tab) => {
if (typeof (tab.expandableTabRenderer) !== 'undefined') {
return true
}
})

const searchResults = channelPageResponse.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs[searchTab].expandableTabRenderer.content.sectionListRenderer
const searchResults = channelPageResponse.data.response.contents.twoColumnBrowseResultsRenderer.tabs[searchTab].expandableTabRenderer.content.sectionListRenderer

let continuation = null

Expand Down Expand Up @@ -545,7 +544,7 @@ class YoutubeGrabber {
const ytGrabHelp = YoutubeGrabberHelper.create(httpAgent)
const decideResponse = await ytGrabHelp.decideUrlRequestType(channelId, 'about?flow=grid&view=0&pbj=1', channelIdType)
const channelPageResponse = decideResponse.response
const headerTabs = channelPageResponse.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs
const headerTabs = channelPageResponse.data.response.contents.twoColumnBrowseResultsRenderer.tabs
const aboutTab = headerTabs.filter((data) => {
if (typeof data.tabRenderer !== 'undefined') {
return data.tabRenderer.title === 'About'
Expand All @@ -571,9 +570,9 @@ class YoutubeGrabber {
const ytGrabHelp = YoutubeGrabberHelper.create(httpAgent)
const decideResponse = await ytGrabHelp.decideUrlRequestType(channelId, 'home?flow=grid&view=0&pbj=1', channelIdType)
const channelPageResponse = decideResponse.response
const headerTabs = channelPageResponse.data[1].response.contents.twoColumnBrowseResultsRenderer.tabs
const headerTabs = channelPageResponse.data.response.contents.twoColumnBrowseResultsRenderer.tabs

const channelMetaData = channelPageResponse.data[1].response.metadata.channelMetadataRenderer
const channelMetaData = channelPageResponse.data.response.metadata.channelMetadataRenderer
const channelName = channelMetaData.title
const channelUrl = channelMetaData.vanityChannelUrl

Expand Down

0 comments on commit 81ba310

Please sign in to comment.