From 384a8e200c953ed5be3ba6a01762e933fd566e45 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Tue, 2 May 2023 23:18:40 +0200 Subject: [PATCH 1/2] Trending: fix mistakes from #3773 --- src/invidious/trending.cr | 18 ++++++++++++++++-- src/invidious/yt_backend/extractors_utils.cr | 13 +++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/invidious/trending.cr b/src/invidious/trending.cr index 74bab1bd..fcaf60d1 100644 --- a/src/invidious/trending.cr +++ b/src/invidious/trending.cr @@ -20,6 +20,20 @@ def fetch_trending(trending_type, region, locale) items, _ = extract_items(initial_data) - # Return items, but ignore categories (e.g featured content) - return items.reject!(Category), plid + extracted = [] of SearchItem + + items.each do |itm| + if itm.is_a?(Category) + # Ignore the smaller categories, as they generally contain a sponsored + # channel, which brings a lot of noise on the trending page. + # See: https://github.com/iv-org/invidious/issues/2989 + next if itm.contents.size < 24 + + extracted.concat extract_category(itm) + else + extracted << itm + end + end + + return extracted, plid end diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr index b247dca8..11d95958 100644 --- a/src/invidious/yt_backend/extractors_utils.cr +++ b/src/invidious/yt_backend/extractors_utils.cr @@ -68,16 +68,17 @@ rescue ex return false end -# This function extracts the SearchItems from a Category. +# This function extracts SearchVideo items from a Category. # Categories are commonly returned in search results and trending pages. def extract_category(category : Category) : Array(SearchVideo) - items = [] of SearchItem + return category.contents.select(SearchVideo) +end - category.contents.each do |item| - target << cate_i if item.is_a?(SearchItem) +# :ditto: +def extract_category(category : Category, &) + category.contents.select(SearchVideo).each do |item| + yield item end - - return items end def extract_selected_tab(tabs) From 90914343ec1a4c89e8bb873fdefa0a8e8ac656df Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Wed, 3 May 2023 00:02:38 +0200 Subject: [PATCH 2/2] Trending: de-duplicate results --- src/invidious/trending.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/invidious/trending.cr b/src/invidious/trending.cr index fcaf60d1..2d9f8a83 100644 --- a/src/invidious/trending.cr +++ b/src/invidious/trending.cr @@ -35,5 +35,6 @@ def fetch_trending(trending_type, region, locale) end end - return extracted, plid + # Deduplicate items before returning results + return extracted.select(SearchVideo).uniq!(&.id), plid end