| 
									
										
										
										
											2021-01-13 11:31:25 +01:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |  INA (Videos) | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | from json import loads | 
					
						
							| 
									
										
										
										
											2020-12-17 09:57:03 +01:00
										 |  |  | from html import unescape | 
					
						
							| 
									
										
										
										
											2020-08-06 17:42:46 +02:00
										 |  |  | from urllib.parse import urlencode | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  | from lxml import html | 
					
						
							|  |  |  | from dateutil import parser | 
					
						
							| 
									
										
										
										
											2020-10-02 18:13:56 +02:00
										 |  |  | from searx.utils import extract_text | 
					
						
							| 
									
										
										
										
											2016-11-30 18:43:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 11:31:25 +01:00
										 |  |  | # about | 
					
						
							|  |  |  | about = { | 
					
						
							|  |  |  |     "website": 'https://www.ina.fr/', | 
					
						
							|  |  |  |     "wikidata_id": 'Q1665109', | 
					
						
							|  |  |  |     "official_api_documentation": None, | 
					
						
							|  |  |  |     "use_official_api": False, | 
					
						
							|  |  |  |     "require_api_key": False, | 
					
						
							|  |  |  |     "results": 'HTML', | 
					
						
							| 
									
										
										
										
											2021-12-21 09:39:03 +01:00
										 |  |  |     "language": 'fr', | 
					
						
							| 
									
										
										
										
											2021-01-13 11:31:25 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | # engine dependent config | 
					
						
							|  |  |  | categories = ['videos'] | 
					
						
							|  |  |  | paging = True | 
					
						
							|  |  |  | page_size = 48 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # search-url | 
					
						
							|  |  |  | base_url = 'https://www.ina.fr' | 
					
						
							|  |  |  | search_url = base_url + '/layout/set/ajax/recherche/result?autopromote=&hf={ps}&b={start}&type=Video&r=&{query}' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # specific xpath variables | 
					
						
							| 
									
										
										
										
											2020-01-02 22:29:28 +01:00
										 |  |  | results_xpath = '//div[contains(@class,"search-results--list")]//div[@class="media-body"]' | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  | url_xpath = './/a/@href' | 
					
						
							|  |  |  | title_xpath = './/h3[@class="h3--title media-heading"]' | 
					
						
							|  |  |  | thumbnail_xpath = './/img/@src' | 
					
						
							|  |  |  | publishedDate_xpath = './/span[@class="broadcast"]' | 
					
						
							|  |  |  | content_xpath = './/p[@class="media-body__summary"]' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # do search-request | 
					
						
							|  |  |  | def request(query, params): | 
					
						
							|  |  |  |     params['url'] = search_url.format(ps=page_size, | 
					
						
							|  |  |  |                                       start=params['pageno'] * page_size, | 
					
						
							|  |  |  |                                       query=urlencode({'q': query})) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return params | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # get response from search-request | 
					
						
							|  |  |  | def response(resp): | 
					
						
							|  |  |  |     results = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # we get html in a JSON container... | 
					
						
							|  |  |  |     response = loads(resp.text) | 
					
						
							| 
									
										
										
										
											2021-03-25 01:20:41 +01:00
										 |  |  |     dom = html.fromstring(response) | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # parse results | 
					
						
							|  |  |  |     for result in dom.xpath(results_xpath): | 
					
						
							|  |  |  |         videoid = result.xpath(url_xpath)[0] | 
					
						
							|  |  |  |         url = base_url + videoid | 
					
						
							| 
									
										
										
										
											2020-12-17 09:57:03 +01:00
										 |  |  |         title = unescape(extract_text(result.xpath(title_xpath))) | 
					
						
							| 
									
										
										
										
											2020-01-02 22:29:28 +01:00
										 |  |  |         try: | 
					
						
							|  |  |  |             thumbnail = extract_text(result.xpath(thumbnail_xpath)[0]) | 
					
						
							|  |  |  |         except: | 
					
						
							|  |  |  |             thumbnail = '' | 
					
						
							|  |  |  |         if thumbnail and thumbnail[0] == '/': | 
					
						
							| 
									
										
										
										
											2016-07-09 17:44:27 +02:00
										 |  |  |             thumbnail = base_url + thumbnail | 
					
						
							|  |  |  |         d = extract_text(result.xpath(publishedDate_xpath)[0]) | 
					
						
							|  |  |  |         d = d.split('/') | 
					
						
							|  |  |  |         # force ISO date to avoid wrong parsing | 
					
						
							|  |  |  |         d = "%s-%s-%s" % (d[2], d[1], d[0]) | 
					
						
							|  |  |  |         publishedDate = parser.parse(d) | 
					
						
							|  |  |  |         content = extract_text(result.xpath(content_xpath)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # append result | 
					
						
							|  |  |  |         results.append({'url': url, | 
					
						
							|  |  |  |                         'title': title, | 
					
						
							|  |  |  |                         'content': content, | 
					
						
							|  |  |  |                         'template': 'videos.html', | 
					
						
							|  |  |  |                         'publishedDate': publishedDate, | 
					
						
							|  |  |  |                         'thumbnail': thumbnail}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # return results | 
					
						
							|  |  |  |     return results |