<commit_before>## Google (Images)
#
# @website     https://www.google.com
# @provide-api yes (https://developers.google.com/web-search/docs/),
#              deprecated!
#
# @using-api   yes
# @results     JSON
# @stable      yes (but deprecated)
# @parse       url, title, img_src

from urllib import urlencode, unquote
from json import loads

# engine dependent config
categories = ['images']
paging = True

# search-url
url = 'https://ajax.googleapis.com/'
search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe=off&filter=off&{query}'


# do search-request
def request(query, params):
    offset = (params['pageno'] - 1) * 8

    params['url'] = search_url.format(query=urlencode({'q': query}),
                                      offset=offset)

    return params


# get response from search-request
def response(resp):
    results = []

    search_res = loads(resp.text)

    # return empty array if there are no results
    if not search_res.get('responseData', {}).get('results'):
        return []

    # parse results
    for result in search_res['responseData']['results']:
        href = result['originalContextUrl']
        title = result['title']
        if 'url' not in result:
            continue
        thumbnail_src = result['tbUrl']

        # append result
        results.append({'url': href,
                        'title': title,
                        'content': result['content'],
                        'thumbnail_src': thumbnail_src,
                        'img_src': unquote(result['url']),
                        'template': 'images.html'})

    # return results<commit_msg>[enh] add safesearch to google_images<commit_after>## Google (Images)
#
# @website     https://www.google.com
# @provide-api yes (https://developers.google.com/web-search/docs/),
#              deprecated!
#
# @using-api   yes
# @results     JSON
# @stable      yes (but deprecated)
# @parse       url, title, img_src

from urllib import urlencode, unquote
from json import loads

# engine dependent config
categories = ['images']
paging = True
safesearch = True

# search-url
url = 'https://ajax.googleapis.com/'
search_url = url + 'ajax/services/search/images?v=1.0&start={offset}&rsz=large&safe={safesearch}&filter=off&{query}'


# do search-request
def request(query, params):
    offset = (params['pageno'] - 1) * 8

    if params['safesearch'] == 2:
        safesearch = 'on'
    else:
        safesearch = 'off'

    params['url'] = search_url.format(query=urlencode({'q': query}),
                                      offset=offset,
                                      safesearch=safesearch)

    return params


# get response from search-request
def response(resp):
    results = []

    search_res = loads(resp.text)

    # return empty array if there are no results
    if not search_res.get('responseData', {}).get('results'):
        return []

    # parse results
    for result in search_res['responseData']['results']:
        href = result['originalContextUrl']
        title = result['title']
        if 'url' not in result:
            continue
        thumbnail_src = result['tbUrl']

        # append result
        results.append({'url': href,
                        'title': title,
                        'content': result['content'],
                        'thumbnail_src': thumbnail_src,
                        'img_src': unquote(result['url']),
                        'template': 'images.html'})

    # return results
{'fraction_non_alphanumeric': 0.1325128792215226, 'fraction_numerical': 0.0025758443045220377, 'mean_word_length': 2.2694106641721237, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1053896', 'n_tokens_mistral': 1031, 'n_tokens_neox': 991, 'n_words': 242}