summaryrefslogtreecommitdiff
path: root/searx/engines/adobe_stock.py
blob: f1b8e13ef105139c77fe90dfe3ecacfc25183079 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-License-Identifier: AGPL-3.0-or-later
"""Adobe Stock (images)
"""

from urllib.parse import urlencode
from searx.utils import gen_useragent

about = {
    "website": 'https://stock.adobe.com/',
    "wikidata_id": 'Q5977430',
    "official_api_documentation": None,
    "use_official_api": False,
    "require_api_key": False,
    "results": 'JSON',
}

categories = ['images']
paging = True

base_url = 'https://stock.adobe.com'

results_per_page = 10
adobe_order = "relevance"  # one of 'relevant', 'featured', 'creation' or 'nb_downloads'


def request(query, params):
    args = {
        'k': query,
        'limit': results_per_page,
        'order': adobe_order,
        'search_page': params['pageno'],
        'search_type': 'pagination',
        'filters[content_type:video]': 0,
        'filters[content_type:audio]': 0,
    }
    params['url'] = f"{base_url}/de/Ajax/Search?{urlencode(args)}"

    # headers required to bypass bot-detection
    params['headers'] = {
        "User-Agent": gen_useragent(),
        "Accept-Language": "en-US,en;q=0.5",
    }

    return params


def response(resp):
    results = []

    json_resp = resp.json()

    for item in json_resp['items'].values():
        results.append(
            {
                'template': 'images.html',
                'url': item['content_url'],
                'title': item['title'],
                'content': '',
                'img_src': item['content_thumb_extra_large_url'],
                'thumbnail_src': item['thumbnail_url'],
                'resolution': f"{item['content_original_width']}x{item['content_original_height']}",
                'img_format': item['format'],
                'author': item['author'],
            }
        )

    return results