~cadence/tube-devel

NewLeaf: Fix search extractor wrongly filtering ads sections against now removed property v1 APPLIED

~lomanic
~lomanic: 1
 Fix search extractor wrongly filtering ads sections against now removed property

 1 files changed, 5 insertions(+), 3 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~cadence/tube-devel/patches/22676/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH NewLeaf] Fix search extractor wrongly filtering ads sections against now removed property Export this patch

~lomanic
From: Lomanic <lomanic@hotmail.fr>

The ads sections had a carouselAdRenderer property, now they have a
promotedSparklesTextSearchRenderer property instead.
As this may change again in the future, we should just get all items
as we discriminate/filter them as videos afterwards with the
videoRenderer property.
---
 extractors/search.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/extractors/search.py b/extractors/search.py
index aeb891c..f354278 100644
--- a/extractors/search.py
+++ b/extractors/search.py
@@ -22,9 +22,11 @@ def extract_search(q):
			content = r.content.decode("utf8")
			yt_initial_data = extract_yt_initial_data(content)
			sections = yt_initial_data["contents"]["twoColumnSearchResultsRenderer"]["primaryContents"]["sectionListRenderer"]["contents"]
			# find the section with the videos, not the one with the ads
			section = next(s for s in sections if "itemSectionRenderer" in s and not (len(s["itemSectionRenderer"]["contents"]) >= 1 and "carouselAdRenderer" in s["itemSectionRenderer"]["contents"][0]))
			items = section["itemSectionRenderer"]["contents"]
			# get all items as we filter videoRenderer entries afterwards
			items = []
			itemSections = [s for s in sections if "itemSectionRenderer" in s]
			for section in itemSections:
				items += section["itemSectionRenderer"]["contents"]
			results = []
			for item in items:
				if "videoRenderer" in item:
-- 
2.30.2
Seems good, thank you so much!