|
@@ -4,12 +4,12 @@
|
4
|
4
|
@using-api yes
|
5
|
5
|
@results JSON
|
6
|
6
|
@stable yes
|
7
|
|
- @parse url, content, size, abstract, author, mtype, time, \
|
8
|
|
- filename, label
|
|
7
|
+ @parse url, content, size, abstract, author, mtype, subtype, time, \
|
|
8
|
+ filename, label, type, embedded
|
9
|
9
|
"""
|
10
|
10
|
|
11
|
11
|
from json import loads
|
12
|
|
-from searx.url_utils import urlencode
|
|
12
|
+from searx.url_utils import urlencode, quote
|
13
|
13
|
from datetime import date, timedelta
|
14
|
14
|
|
15
|
15
|
# engine dependent config
|
|
@@ -19,9 +19,15 @@ time_range_support = True
|
19
|
19
|
# parameters from settings.yml
|
20
|
20
|
base_url = None
|
21
|
21
|
search_dir = ''
|
|
22
|
+mount_prefix = None
|
22
|
23
|
dl_prefix = None
|
23
|
24
|
|
|
25
|
+# embedded
|
|
26
|
+embedded_url = '<{type} controls height="166px" ' +\
|
|
27
|
+ 'src="{url}" type="{mtype}"></{type}>'
|
24
|
28
|
|
|
29
|
+
|
|
30
|
+# helper functions
|
25
|
31
|
def get_time_range(time_range):
|
26
|
32
|
sw = {
|
27
|
33
|
'day': 1,
|
|
@@ -61,7 +67,7 @@ def response(resp):
|
61
|
67
|
|
62
|
68
|
for result in response_json.get('results', []):
|
63
|
69
|
title = result['label']
|
64
|
|
- url = result['url'].replace('file:///export', dl_prefix)
|
|
70
|
+ url = result['url'].replace('file://' + mount_prefix, dl_prefix)
|
65
|
71
|
content = u'{}'.format(result['snippet'])
|
66
|
72
|
|
67
|
73
|
# append result
|
|
@@ -77,6 +83,21 @@ def response(resp):
|
77
|
83
|
if result[parameter]:
|
78
|
84
|
item[parameter] = result[parameter]
|
79
|
85
|
|
|
86
|
+ # facilitate preview support for known mime types
|
|
87
|
+ if 'mtype' in result:
|
|
88
|
+ (mtype, subtype) = result['mtype'].split('/')
|
|
89
|
+ item['type'] = mtype
|
|
90
|
+ item['subtype'] = subtype
|
|
91
|
+
|
|
92
|
+ if mtype in ['audio', 'video']:
|
|
93
|
+ item['embedded'] = embedded_url.format(
|
|
94
|
+ type=type,
|
|
95
|
+ url=quote(url.encode('utf8'), '/:'),
|
|
96
|
+ mtype=result['mtype'])
|
|
97
|
+
|
|
98
|
+ if mtype in ['image'] and subtype in ['bmp', 'gif', 'jpeg', 'png']:
|
|
99
|
+ item['img_src'] = url
|
|
100
|
+
|
80
|
101
|
results.append(item)
|
81
|
102
|
|
82
|
103
|
if 'nres' in response_json:
|