mirror of
				https://git.sr.ht/~cadence/NewLeaf
				synced 2025-11-03 21:57:29 +00:00 
			
		
		
		
	Fix search extractor ad section filtering
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.
This commit is contained in:
		
							parent
							
								
									57b0a88a2e
								
							
						
					
					
						commit
						f0c9708d99
					
				@ -21,10 +21,15 @@ def extract_search(q):
 | 
			
		||||
			r.raise_for_status()
 | 
			
		||||
			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"]
 | 
			
		||||
			# youtube searches contain a lot of random stuff, just grab it all for now, then filter to `videoRenderer` later
 | 
			
		||||
			itemSections = [s for s in sections if "itemSectionRenderer" in s]
 | 
			
		||||
 | 
			
		||||
			items = []
 | 
			
		||||
			for section in itemSections:
 | 
			
		||||
				items += section["itemSectionRenderer"]["contents"]
 | 
			
		||||
 | 
			
		||||
			results = []
 | 
			
		||||
			for item in items:
 | 
			
		||||
				if "videoRenderer" in item:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user