From 3c9a6dd8e6c114cda16426fffb34cce60f2535c8 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 8 Sep 2019 10:32:52 -0700 Subject: Search: Fix advertisements for google products like home/stadia breaking search results --- youtube/search.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'youtube/search.py') diff --git a/youtube/search.py b/youtube/search.py index e35d0cb..e167279 100644 --- a/youtube/search.py +++ b/youtube/search.py @@ -78,7 +78,11 @@ def get_search_page(): estimated_results = int(info[1]['response']['estimatedResults']) estimated_pages = ceil(estimated_results/20) - results = info[1]['response']['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'] + + # almost always is the first "section", but if there's an advertisement for a google product like Stadia or Home in the search results, then that becomes the first "section" and the search results are in the second. So just join all of them for resiliency + results = [] + for section in info[1]['response']['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']['contents']: + results += section['itemSectionRenderer']['contents'] parsed_results = [] corrections = {'type': None} -- cgit v1.2.3