Skip to content
Closed
Show file tree
Hide file tree
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
66 changes: 66 additions & 0 deletions src/renderer/helpers/api/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,42 @@ export async function getLocalChannel(id) {
return result
}

export async function getLocalChannelWithVideos(id) {
const innertube = await createInnertube()

try {
const response = await innertube.actions.execute(Endpoints.BrowseEndpoint.PATH, Endpoints.BrowseEndpoint.build({
browse_id: id,
params: 'EgZ2aWRlb3PyBgQKAjoA'
// protobuf for the videos tab (this is the one that YouTube uses,
// it has some empty fields in the protobuf but it doesn't work if you remove them)
}))

const videosTab = new YT.Channel(null, response)

// if the channel doesn't have a videos tab, YouTube returns the home tab instead
// so we need to check that we got the right tab
if (videosTab.current_tab?.endpoint.metadata.url?.endsWith('/videos')) {
return {
channel: videosTab,
videos: parseLocalChannelVideos(videosTab.videos, videosTab.header.author),
}
} else {
return {
channel: videosTab,
videos: [],
}
}
} catch (error) {
console.error(error)
if (error instanceof Utils.ChannelError) {
return {}
} else {
throw error
}
}
}

export async function getLocalChannelVideos(id) {
const innertube = await createInnertube()

Expand Down Expand Up @@ -247,6 +283,36 @@ export async function getLocalChannelVideos(id) {
}
}

export async function getLocalChannelLiveStreams(id) {
const innertube = await createInnertube()

try {
const response = await innertube.actions.execute(Endpoints.BrowseEndpoint.PATH, Endpoints.BrowseEndpoint.build({
browse_id: id,
params: 'EgdzdHJlYW1z8gYECgJ6AA%3D%3D'
// protobuf for the live tab (this is the one that YouTube uses,
// it has some empty fields in the protobuf but it doesn't work if you remove them)
}))

const liveStreamsTab = new YT.Channel(null, response)

// 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')) {
return parseLocalChannelVideos(liveStreamsTab.videos, liveStreamsTab.header.author)
} else {
return []
}
} catch (error) {
console.error(error)
if (error instanceof Utils.ChannelError) {
return null
} else {
throw error
}
}
}

/**
* @param {import('youtubei.js').YTNodes.Video[]} videos
* @param {Misc.Author} author
Expand Down
19 changes: 14 additions & 5 deletions src/renderer/views/Subscriptions/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import FtChannelBubble from '../../components/ft-channel-bubble/ft-channel-bubbl
import { MAIN_PROFILE_ID } from '../../../constants'
import { calculatePublishedDate, copyToClipboard, showToast } from '../../helpers/utils'
import { invidiousAPICall } from '../../helpers/api/invidious'
import { getLocalChannelVideos } from '../../helpers/api/local'
import {
getLocalChannelLiveStreams,
getLocalChannelWithVideos,
} from '../../helpers/api/local'

export default defineComponent({
name: 'Subscriptions',
Expand Down Expand Up @@ -152,7 +155,7 @@ export default defineComponent({
}

let useRss = this.useRssFeeds
if (this.activeSubscriptionList.length >= 125 && !useRss) {
if (this.activeSubscriptionList.length >= 62 && !useRss) {
showToast(
this.$t('Subscriptions["This profile has a large number of subscriptions. Forcing RSS to avoid rate limiting"]'),
10000
Expand Down Expand Up @@ -268,12 +271,18 @@ export default defineComponent({

getChannelVideosLocalScraper: async function (channel, failedAttempts = 0) {
try {
const videos = await getLocalChannelVideos(channel.id)

if (videos === null) {
const videos = []
const { channel: localChannel, videos: normalVideos } = await getLocalChannelWithVideos(channel.id)
if (localChannel == null) {
this.errorChannels.push(channel)
return []
}
if (localChannel.has_videos) {
videos.push(...normalVideos)
}
if (!this.hideLiveStreams && localChannel.has_live_streams) {
videos.push(...await getLocalChannelLiveStreams(channel.id))
}

videos.map(video => {
if (video.liveNow) {
Expand Down