Skip to content

Commit

Permalink
Workaround YouTube returning empty pages on the channel live tab (#4914)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Apr 9, 2024
1 parent c7c40d7 commit 490c51f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,24 @@ export async function getLocalChannelLiveStreams(id) {
// it has some empty fields in the protobuf but it doesn't work if you remove them)
}))

const liveStreamsTab = new YT.Channel(null, response)
let liveStreamsTab = new YT.Channel(innertube.actions, response)
const { id: channelId = id, name, thumbnailUrl } = parseLocalChannelHeader(liveStreamsTab)

let videos

// if the channel doesn't have a live tab, YouTube returns the home tab instead
// so we need to check that we got the right tab
if (liveStreamsTab.current_tab?.endpoint.metadata.url?.endsWith('/streams')) {
videos = parseLocalChannelVideos(liveStreamsTab.videos, channelId, name)
// work around YouTube bug where it will return a bunch of responses with only continuations in them
// e.g. https://www.youtube.com/@TWLIVES/streams

let tempVideos = liveStreamsTab.videos
while (tempVideos.length === 0 && liveStreamsTab.has_continuation) {
liveStreamsTab = await liveStreamsTab.getContinuation()
tempVideos = liveStreamsTab.videos
}

videos = parseLocalChannelVideos(tempVideos, channelId, name)
} else {
videos = []
}
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,16 @@ export default defineComponent({
return
}

this.latestLive = parseLocalChannelVideos(liveTab.videos, this.id, this.channelName)
// work around YouTube bug where it will return a bunch of responses with only continuations in them
// e.g. https://www.youtube.com/@TWLIVES/streams

let videos = liveTab.videos
while (videos.length === 0 && liveTab.has_continuation) {
liveTab = await liveTab.getContinuation()
videos = liveTab.videos
}

this.latestLive = parseLocalChannelVideos(videos, this.id, this.channelName)
this.liveContinuationData = liveTab.has_continuation ? liveTab : null
this.isElementListLoading = false

Expand Down

0 comments on commit 490c51f

Please sign in to comment.