2021-01-13 11:31:25 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2015-05-02 15:45:17 +02:00
|
|
|
"""
|
|
|
|
1x (Images)
|
|
|
|
"""
|
2015-02-01 11:27:28 +01:00
|
|
|
|
2020-12-07 15:46:00 +01:00
|
|
|
from lxml import html, etree
|
2020-08-06 17:42:46 +02:00
|
|
|
from urllib.parse import urlencode, urljoin
|
2020-12-07 15:46:00 +01:00
|
|
|
from searx.utils import extract_text, eval_xpath_list, eval_xpath_getindex
|
2015-02-01 11:27:28 +01:00
|
|
|
|
2021-01-13 11:31:25 +01:00
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://1x.com/',
|
|
|
|
"wikidata_id": None,
|
|
|
|
"official_api_documentation": None,
|
|
|
|
"use_official_api": False,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'HTML',
|
|
|
|
}
|
|
|
|
|
2015-02-01 11:27:28 +01:00
|
|
|
# engine dependent config
|
|
|
|
categories = ['images']
|
|
|
|
paging = False
|
|
|
|
|
2015-06-06 19:44:41 +02:00
|
|
|
# search-url
|
2015-06-06 19:23:07 +02:00
|
|
|
base_url = 'https://1x.com'
|
2016-01-18 12:47:31 +01:00
|
|
|
search_url = base_url + '/backend/search.php?{query}'
|
2020-12-07 15:46:00 +01:00
|
|
|
gallery_url = 'https://gallery.1x.com/'
|
2015-02-01 11:27:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
# do search-request
|
|
|
|
def request(query, params):
|
|
|
|
params['url'] = search_url.format(query=urlencode({'q': query}))
|
|
|
|
|
|
|
|
return params
|
|
|
|
|
|
|
|
|
|
|
|
# get response from search-request
|
|
|
|
def response(resp):
|
|
|
|
results = []
|
2020-12-07 15:46:00 +01:00
|
|
|
xmldom = etree.fromstring(resp.content)
|
|
|
|
xmlsearchresult = eval_xpath_getindex(xmldom, '//searchresult', 0)
|
|
|
|
dom = html.fragment_fromstring(xmlsearchresult.text, create_parent='div')
|
|
|
|
for link in eval_xpath_list(dom, '/div/table/tr/td/div[2]//a'):
|
2015-02-01 11:27:28 +01:00
|
|
|
url = urljoin(base_url, link.attrib.get('href'))
|
2019-10-16 13:27:05 +02:00
|
|
|
title = extract_text(link)
|
2020-12-07 15:46:00 +01:00
|
|
|
thumbnail_src = urljoin(gallery_url, eval_xpath_getindex(link, './/img', 0).attrib['src'])
|
2015-02-01 11:27:28 +01:00
|
|
|
|
|
|
|
# append result
|
2021-12-27 09:26:22 +01:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': url,
|
|
|
|
'title': title,
|
|
|
|
'img_src': thumbnail_src,
|
|
|
|
'content': '',
|
|
|
|
'thumbnail_src': thumbnail_src,
|
|
|
|
'template': 'images.html',
|
|
|
|
}
|
|
|
|
)
|
2015-02-01 11:27:28 +01:00
|
|
|
|
|
|
|
# return results
|
|
|
|
return results
|