Deduplicate videos on the default trending tab (#3492)

This commit is contained in:
absidue 2023-05-07 14:52:39 +02:00 committed by GitHub
parent a9fa327c9b
commit 6ef572d1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,7 +75,7 @@ export async function getLocalPlaylist(id) {
/**
* @param {string} location
* @param {string} tab
* @param {'default'|'music'|'gaming'|'movies'} tab
* @param {import('youtubei.js').Mixins.TabbedFeed|null} instance
*/
export async function getLocalTrending(location, tab, instance) {
@ -88,9 +88,24 @@ export async function getLocalTrending(location, tab, instance) {
const tabIndex = ['default', 'music', 'gaming', 'movies'].indexOf(tab)
const resultsInstance = await instance.getTabByName(instance.tabs[tabIndex])
const results = resultsInstance.videos
let results
// the default tab can have duplicate videos so we need to deduplicate them
if (tab === 'default') {
const alreadySeenIds = []
results = []
resultsInstance.videos.forEach(video => {
if (video.type === 'Video' && !alreadySeenIds.includes(video.id)) {
alreadySeenIds.push(video.id)
results.push(parseLocalListVideo(video))
}
})
} else {
results = resultsInstance.videos
.filter((video) => video.type === 'Video')
.map(parseLocalListVideo)
}
return {
results,