|
@@ -0,0 +1,115 @@
|
|
1
|
+"""
|
|
2
|
+FindX (General, Images, Videos)
|
|
3
|
+
|
|
4
|
+@website https://www.findx.com
|
|
5
|
+@provide-api no
|
|
6
|
+@using-api no
|
|
7
|
+@results HTML
|
|
8
|
+@stable no
|
|
9
|
+@parse url, title, content, embedded, img_src, thumbnail_src
|
|
10
|
+"""
|
|
11
|
+
|
|
12
|
+from dateutil import parser
|
|
13
|
+from json import loads
|
|
14
|
+import re
|
|
15
|
+
|
|
16
|
+from lxml import html
|
|
17
|
+
|
|
18
|
+from searx import logger
|
|
19
|
+from searx.engines.xpath import extract_text
|
|
20
|
+from searx.engines.youtube_noapi import base_youtube_url, embedded_url
|
|
21
|
+from searx.url_utils import urlencode
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+paging = True
|
|
25
|
+results_xpath = '//script[@id="initial-state"]'
|
|
26
|
+search_url = 'https://www.findx.com/{category}?{q}'
|
|
27
|
+type_map = {
|
|
28
|
+ 'none': 'web',
|
|
29
|
+ 'general': 'web',
|
|
30
|
+ 'images': 'images',
|
|
31
|
+ 'videos': 'videos',
|
|
32
|
+}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+def request(query, params):
|
|
36
|
+ params['url'] = search_url.format(
|
|
37
|
+ category=type_map[params['category']],
|
|
38
|
+ q=urlencode({
|
|
39
|
+ 'q': query,
|
|
40
|
+ 'page': params['pageno']
|
|
41
|
+ })
|
|
42
|
+ )
|
|
43
|
+ return params
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+def response(resp):
|
|
47
|
+ dom = html.fromstring(resp.text)
|
|
48
|
+ results_raw_json = dom.xpath(results_xpath)
|
|
49
|
+ results_json = loads(extract_text(results_raw_json))
|
|
50
|
+
|
|
51
|
+ if len(results_json['web']['results']) > 0:
|
|
52
|
+ return _general_results(results_json['web']['results'])
|
|
53
|
+
|
|
54
|
+ if len(results_json['images']['results']) > 0:
|
|
55
|
+ return _images_results(results_json['images']['results'])
|
|
56
|
+
|
|
57
|
+ if len(results_json['video']['results']) > 0:
|
|
58
|
+ return _videos_results(results_json['video']['results'])
|
|
59
|
+
|
|
60
|
+ return []
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+def _general_results(general_results):
|
|
64
|
+ results = []
|
|
65
|
+ for result in general_results:
|
|
66
|
+ results.append({
|
|
67
|
+ 'url': result['url'],
|
|
68
|
+ 'title': result['title'],
|
|
69
|
+ 'content': result['sum'],
|
|
70
|
+ })
|
|
71
|
+ return results
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+def _images_results(image_results):
|
|
75
|
+ results = []
|
|
76
|
+ for result in image_results:
|
|
77
|
+ results.append({
|
|
78
|
+ 'url': result['sourceURL'],
|
|
79
|
+ 'title': result['title'],
|
|
80
|
+ 'content': result['source'],
|
|
81
|
+ 'thumbnail_src': _extract_url(result['assets']['thumb']['url']),
|
|
82
|
+ 'img_src': _extract_url(result['assets']['file']['url']),
|
|
83
|
+ 'template': 'images.html',
|
|
84
|
+ })
|
|
85
|
+ return results
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+def _videos_results(video_results):
|
|
89
|
+ results = []
|
|
90
|
+ for result in video_results:
|
|
91
|
+ if not result['kind'].startswith('youtube'):
|
|
92
|
+ logger.warn('Unknown video kind in findx: {}'.format(result['kind']))
|
|
93
|
+ continue
|
|
94
|
+
|
|
95
|
+ description = result['snippet']['description']
|
|
96
|
+ if len(description) > 300:
|
|
97
|
+ description = description[:300] + '...'
|
|
98
|
+
|
|
99
|
+ results.append({
|
|
100
|
+ 'url': base_youtube_url + result['id'],
|
|
101
|
+ 'title': result['snippet']['title'],
|
|
102
|
+ 'content': description,
|
|
103
|
+ 'thumbnail': _extract_url(result['snippet']['thumbnails']['default']['url']),
|
|
104
|
+ 'publishedDate': parser.parse(result['snippet']['publishedAt']),
|
|
105
|
+ 'embedded': embedded_url.format(videoid=result['id']),
|
|
106
|
+ 'template': 'videos.html',
|
|
107
|
+ })
|
|
108
|
+ return results
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+def _extract_url(url):
|
|
112
|
+ matching = re.search('(/https?://[^)]+)', url)
|
|
113
|
+ if matching:
|
|
114
|
+ return matching.group(0)[1:]
|
|
115
|
+ return ''
|