37from typing
import List, Dict, Any, Optional
94def request(query: str, params: Dict[str, Any]) -> Dict[str, Any]:
95 lang: str = traits.get_language(params[
"language"], traits.all_locale)
98 +
"/s/{search_query}/?page={pageno}"
99 +
"&yearFrom={zlib_year_from}"
100 +
"&yearTo={zlib_year_to}"
101 +
"&languages[]={lang}"
102 +
"&extensions[]={zlib_ext}"
104 params[
"url"] = search_url.format(
105 search_query=quote(query),
106 pageno=params[
"pageno"],
108 zlib_year_from=zlib_year_from,
109 zlib_year_to=zlib_year_to,
112 params[
"verify"] =
False
179 """Fetch languages and other search arguments from zlibrary's search form."""
186 def _use_old_values():
188 engine_traits.all_locale = ENGINE_TRAITS[
"z-library"][
"all_locale"]
189 engine_traits.custom = ENGINE_TRAITS[
"z-library"][
"custom"]
190 engine_traits.languages = ENGINE_TRAITS[
"z-library"][
"languages"]
193 resp = get(base_url, verify=
False)
194 except SearxException
as exc:
195 print(f
"ERROR: zlibrary domain '{base_url}' is seized?")
201 raise RuntimeError(
"Response from zlibrary's search page is not OK.")
202 dom = html.fromstring(resp.text)
205 print(f
"ERROR: zlibrary domain is seized: {base_url}")
209 engine_traits.all_locale =
""
210 engine_traits.custom[
"ext"] = []
211 engine_traits.custom[
"year_from"] = []
212 engine_traits.custom[
"year_to"] = []
214 for year
in eval_xpath_list(dom,
"//div[@id='advSearch-noJS']//select[@id='sf_yearFrom']/option"):
215 engine_traits.custom[
"year_from"].append(year.get(
"value"))
217 for year
in eval_xpath_list(dom,
"//div[@id='advSearch-noJS']//select[@id='sf_yearTo']/option"):
218 engine_traits.custom[
"year_to"].append(year.get(
"value"))
220 for ext
in eval_xpath_list(dom,
"//div[@id='advSearch-noJS']//select[@id='sf_extensions']/option"):
221 value: Optional[str] = ext.get(
"value")
224 engine_traits.custom[
"ext"].append(value)
228 language_name_locale_map: Dict[str, babel.Locale] = {}
229 for locale
in babel.core.localedata.locale_identifiers():
231 loc = babel.Locale.parse(locale)
232 if loc.english_name
is None:
234 language_name_locale_map[loc.english_name.lower()] = loc
236 for x
in eval_xpath_list(dom,
"//div[@id='advSearch-noJS']//select[@id='sf_languages']/option"):
237 eng_lang = x.get(
"value")
241 locale = language_name_locale_map[eng_lang.lower()]
246 sxng_lang = language_tag(locale)
247 conflict = engine_traits.languages.get(sxng_lang)
249 if conflict != eng_lang:
250 print(
"CONFLICT: babel %s --> %s, %s" % (sxng_lang, conflict, eng_lang))
252 engine_traits.languages[sxng_lang] = eng_lang