|
@@ -12,12 +12,9 @@
|
12
|
12
|
@todo rewrite to api
|
13
|
13
|
"""
|
14
|
14
|
|
15
|
|
-
|
|
15
|
+from json import loads
|
16
|
16
|
from urllib import urlencode
|
17
|
17
|
from urlparse import urljoin
|
18
|
|
-from lxml import html
|
19
|
|
-import re
|
20
|
|
-from searx.engines.xpath import extract_text
|
21
|
18
|
|
22
|
19
|
# engine dependent config
|
23
|
20
|
categories = ['images']
|
|
@@ -25,13 +22,27 @@ paging = True
|
25
|
22
|
|
26
|
23
|
# search-url
|
27
|
24
|
base_url = 'https://500px.com'
|
28
|
|
-search_url = base_url + '/search?search?page={pageno}&type=photos&{query}'
|
|
25
|
+search_url = 'https://api.500px.com/v1/photos/search?type=photos'\
|
|
26
|
+ '&{query}'\
|
|
27
|
+ '&image_size%5B%5D=4'\
|
|
28
|
+ '&image_size%5B%5D=20'\
|
|
29
|
+ '&image_size%5B%5D=21'\
|
|
30
|
+ '&image_size%5B%5D=1080'\
|
|
31
|
+ '&image_size%5B%5D=1600'\
|
|
32
|
+ '&image_size%5B%5D=2048'\
|
|
33
|
+ '&include_states=true'\
|
|
34
|
+ '&formats=jpeg%2Clytro'\
|
|
35
|
+ '&include_tags=true'\
|
|
36
|
+ '&exclude_nude=true'\
|
|
37
|
+ '&page={pageno}'\
|
|
38
|
+ '&rpp=50'\
|
|
39
|
+ '&sdk_key=b68e60cff4c929bedea36ca978830c5caca790c3'
|
29
|
40
|
|
30
|
41
|
|
31
|
42
|
# do search-request
|
32
|
43
|
def request(query, params):
|
33
|
44
|
params['url'] = search_url.format(pageno=params['pageno'],
|
34
|
|
- query=urlencode({'q': query}))
|
|
45
|
+ query=urlencode({'term': query}))
|
35
|
46
|
|
36
|
47
|
return params
|
37
|
48
|
|
|
@@ -40,19 +51,16 @@ def request(query, params):
|
40
|
51
|
def response(resp):
|
41
|
52
|
results = []
|
42
|
53
|
|
43
|
|
- dom = html.fromstring(resp.text)
|
44
|
|
- regex = re.compile(r'3\.jpg.*$')
|
|
54
|
+ response_json = loads(resp.text)
|
45
|
55
|
|
46
|
56
|
# parse results
|
47
|
|
- for result in dom.xpath('//div[@class="photo"]'):
|
48
|
|
- link = result.xpath('.//a')[0]
|
49
|
|
- url = urljoin(base_url, link.attrib.get('href'))
|
50
|
|
- title = extract_text(result.xpath('.//div[@class="title"]'))
|
51
|
|
- thumbnail_src = link.xpath('.//img')[0].attrib.get('src')
|
52
|
|
- # To have a bigger thumbnail, uncomment the next line
|
53
|
|
- # thumbnail_src = regex.sub('4.jpg', thumbnail_src)
|
54
|
|
- content = extract_text(result.xpath('.//div[@class="info"]'))
|
55
|
|
- img_src = regex.sub('2048.jpg', thumbnail_src)
|
|
57
|
+ for result in response_json['photos']:
|
|
58
|
+ url = urljoin(base_url, result['url'])
|
|
59
|
+ title = result['name']
|
|
60
|
+ # last index is the biggest resolution
|
|
61
|
+ img_src = result['image_url'][-1]
|
|
62
|
+ thumbnail_src = result['image_url'][0]
|
|
63
|
+ content = result['description'] or ''
|
56
|
64
|
|
57
|
65
|
# append result
|
58
|
66
|
results.append({'url': url,
|