Skip to content

Commit

Permalink
Local API: List related games in featured channels section (#4562)
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue authored Jan 30, 2024
1 parent 205924c commit d0e33fb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
block-size: 50px;
border-radius: 100%;
-webkit-border-radius: 100%;
object-fit: cover;
}

.selected {
Expand Down
48 changes: 37 additions & 11 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ export default defineComponent({
const expectedId = this.id

try {
/** @type {import('youtubei.js').YT.Channel|undefined} */
let channel
if (!this.channelInstance) {
channel = await getLocalChannel(this.id)
Expand Down Expand Up @@ -651,19 +652,44 @@ export default defineComponent({
this.bannerUrl = null
}

this.relatedChannels = channel.channels.map(({ author }) => {
let thumbnailUrl = author.best_thumbnail.url
let relatedChannels = channel.channels.map(({ author }) => ({
name: author.name,
id: author.id,
thumbnailUrl: author.best_thumbnail.url
}))

if (thumbnailUrl.startsWith('//')) {
thumbnailUrl = `https:${thumbnailUrl}`
}
if (channel.memo.has('GameDetails')) {
/** @type {import('youtubei.js').YTNodes.GameDetails[]} */
const games = channel.memo.get('GameDetails')

return {
name: author.name,
id: author.id,
thumbnailUrl
}
})
relatedChannels.push(...games.map(game => ({
id: game.endpoint.payload.browseId,
name: game.title.text,
thumbnailUrl: game.box_art[0].url
})))
}

if (relatedChannels.length > 0) {
/** @type {Set<string>} */
const knownChannelIds = new Set()

relatedChannels = relatedChannels.filter(channel => {
if (!knownChannelIds.has(channel.id)) {
knownChannelIds.add(channel.id)
return true
}

return false
})

relatedChannels.forEach(channel => {
if (channel.thumbnailUrl.startsWith('//')) {
channel.thumbnailUrl = `https:${channel.thumbnailUrl}`
}
})
}

this.relatedChannels = relatedChannels

this.channelInstance = channel

Expand Down

0 comments on commit d0e33fb

Please sign in to comment.