Ejemplo n.º 1
0
def request(query, params):
    """Google-Video search request"""

    language, country, lang_country = get_lang_country(
        # pylint: disable=undefined-variable
        params,
        supported_languages,
        language_aliases,
    )
    subdomain = "www." + google_domains.get(country.upper(), "google.com")

    query_url = ("https://" + subdomain + "/search" + "?" +
                 urlencode({
                     "q": query,
                     "tbm": "isch",
                     "hl": lang_country,
                     "lr": "lang_" + language,
                     "ie": "utf8",
                     "oe": "utf8",
                     "num": 30,
                 }))

    if params["time_range"] in time_range_dict:
        query_url += "&" + urlencode(
            {"tbs": "qdr:" + time_range_dict[params["time_range"]]})
    if params["safesearch"]:
        query_url += "&" + urlencode(
            {"safe": filter_mapping[params["safesearch"]]})

    params["url"] = query_url
    logger.debug("query_url --> %s", query_url)

    params["headers"]["Accept-Language"] = "%s,%s;q=0.8,%s;q=0.5" % (
        lang_country,
        language,
        language,
    )
    logger.debug("HTTP Accept-Language --> %s",
                 params["headers"]["Accept-Language"])
    params["headers"][
        "Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"
    # params['google_subdomain'] = subdomain
    return params
Ejemplo n.º 2
0
def request(query, params):
    """Google-Video search request"""

    language, country, lang_country = get_lang_country(
        # pylint: disable=undefined-variable
        params,
        supported_languages,
        language_aliases)
    subdomain = 'www.' + google_domains.get(country.upper(), 'google.com')

    query_url = 'https://' + subdomain + '/search' + "?" + urlencode(
        {
            'q': query,
            'tbm': "isch",
            'hl': lang_country,
            'lr': "lang_" + language,
            'ie': "utf8",
            'oe': "utf8",
            'num': 30,
        })

    if params['time_range'] in time_range_dict:
        query_url += '&' + urlencode(
            {'tbs': 'qdr:' + time_range_dict[params['time_range']]})
    if params['safesearch']:
        query_url += '&' + urlencode(
            {'safe': filter_mapping[params['safesearch']]})

    params['url'] = query_url
    logger.debug("query_url --> %s", query_url)

    params['headers']['Accept-Language'] = ("%s,%s;q=0.8,%s;q=0.5" %
                                            (lang_country, language, language))
    logger.debug("HTTP Accept-Language --> %s",
                 params['headers']['Accept-Language'])
    params['headers']['Accept'] = (
        'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
    )
    # params['google_subdomain'] = subdomain
    return params