2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
"""
|
|
|
|
INA (Videos)
|
|
|
|
"""
|
2016-07-09 15:44:27 +00:00
|
|
|
|
2020-12-17 08:57:03 +00:00
|
|
|
from html import unescape
|
2020-08-06 15:42:46 +00:00
|
|
|
from urllib.parse import urlencode
|
2016-07-09 15:44:27 +00:00
|
|
|
from lxml import html
|
2022-01-28 21:13:48 +00:00
|
|
|
from searx.utils import extract_text, eval_xpath, eval_xpath_list, eval_xpath_getindex
|
2016-11-30 17:43:03 +00:00
|
|
|
|
2021-01-13 10:31:25 +00: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 08:39:03 +00:00
|
|
|
"language": 'fr',
|
2021-01-13 10:31:25 +00:00
|
|
|
}
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# engine dependent config
|
|
|
|
categories = ['videos']
|
|
|
|
paging = True
|
2022-01-28 21:13:48 +00:00
|
|
|
page_size = 12
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# search-url
|
|
|
|
base_url = 'https://www.ina.fr'
|
2022-01-28 21:13:48 +00:00
|
|
|
search_url = base_url + '/ajax/recherche?{query}&espace=1&sort=pertinence&order=desc&offset={start}&modified=size'
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# specific xpath variables
|
2022-01-28 21:13:48 +00:00
|
|
|
results_xpath = '//div[@id="searchHits"]/div'
|
2016-07-09 15:44:27 +00:00
|
|
|
url_xpath = './/a/@href'
|
2022-01-28 21:13:48 +00:00
|
|
|
title_xpath = './/div[contains(@class,"title-bloc-small")]'
|
|
|
|
content_xpath = './/div[contains(@class,"sous-titre-fonction")]'
|
|
|
|
thumbnail_xpath = './/img/@data-src'
|
|
|
|
publishedDate_xpath = './/div[contains(@class,"dateAgenda")]'
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
# do search-request
|
|
|
|
def request(query, params):
|
2022-01-28 21:13:48 +00:00
|
|
|
params['url'] = search_url.format(start=params['pageno'] * page_size, query=urlencode({'q': query}))
|
2016-07-09 15:44:27 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
|
|
|
# we get html in a JSON container...
|
2022-01-28 21:13:48 +00:00
|
|
|
dom = html.fromstring(resp.text)
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# parse results
|
2022-01-28 21:13:48 +00:00
|
|
|
for result in eval_xpath_list(dom, results_xpath):
|
|
|
|
url_relative = eval_xpath_getindex(result, url_xpath, 0)
|
|
|
|
url = base_url + url_relative
|
|
|
|
title = unescape(extract_text(eval_xpath(result, title_xpath)))
|
|
|
|
thumbnail = extract_text(eval_xpath(result, thumbnail_xpath))
|
|
|
|
content = extract_text(eval_xpath(result, publishedDate_xpath)) + extract_text(
|
|
|
|
eval_xpath(result, content_xpath)
|
|
|
|
)
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# append result
|
2021-12-27 08:26:22 +00:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': url,
|
|
|
|
'title': title,
|
|
|
|
'content': content,
|
|
|
|
'template': 'videos.html',
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
}
|
|
|
|
)
|
2016-07-09 15:44:27 +00:00
|
|
|
|
|
|
|
# return results
|
|
|
|
return results
|