add time range search for youtube noapi
This commit is contained in:
		
							parent
							
								
									f70d405202
								
							
						
					
					
						commit
						d2e0cbafb2
					
				| @ -17,10 +17,15 @@ from searx.utils import list_get | |||||||
| categories = ['videos', 'music'] | categories = ['videos', 'music'] | ||||||
| paging = True | paging = True | ||||||
| language_support = False | language_support = False | ||||||
|  | time_range_support = True | ||||||
| 
 | 
 | ||||||
| # search-url | # search-url | ||||||
| base_url = 'https://www.youtube.com/results' | base_url = 'https://www.youtube.com/results' | ||||||
| search_url = base_url + '?search_query={query}&page={page}' | search_url = base_url + '?search_query={query}&page={page}' | ||||||
|  | time_range_url = '&sp=EgII{time_range}%253D%253D' | ||||||
|  | time_range_dict = {'day': 'Ag', | ||||||
|  |                    'week': 'Aw', | ||||||
|  |                    'month': 'BA'} | ||||||
| 
 | 
 | ||||||
| embedded_url = '<iframe width="540" height="304" ' +\ | embedded_url = '<iframe width="540" height="304" ' +\ | ||||||
|     'data-src="//www.youtube-nocookie.com/embed/{videoid}" ' +\ |     'data-src="//www.youtube-nocookie.com/embed/{videoid}" ' +\ | ||||||
| @ -47,6 +52,8 @@ def extract_text_from_dom(result, xpath): | |||||||
| def request(query, params): | def request(query, params): | ||||||
|     params['url'] = search_url.format(query=quote_plus(query), |     params['url'] = search_url.format(query=quote_plus(query), | ||||||
|                                       page=params['pageno']) |                                       page=params['pageno']) | ||||||
|  |     if params['time_range'] in time_range_dict: | ||||||
|  |         params['url'] += time_range_url.format(time_range=time_range_dict[params['time_range']]) | ||||||
| 
 | 
 | ||||||
|     return params |     return params | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ class TestYoutubeNoAPIEngine(SearxTestCase): | |||||||
|         query = 'test_query' |         query = 'test_query' | ||||||
|         dicto = defaultdict(dict) |         dicto = defaultdict(dict) | ||||||
|         dicto['pageno'] = 0 |         dicto['pageno'] = 0 | ||||||
|  |         dicto['time_range'] = '' | ||||||
|         params = youtube_noapi.request(query, dicto) |         params = youtube_noapi.request(query, dicto) | ||||||
|         self.assertIn('url', params) |         self.assertIn('url', params) | ||||||
|         self.assertIn(query, params['url']) |         self.assertIn(query, params['url']) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Noémi Ványi
						Noémi Ványi