on master help sign in
Merge pull request #1642 from dalf/start-speed
d0dd296Alexandre Flament
searx/engines/soundcloud.py+4−2
@@ -28,8 +28,10 @@ categories = ['music']
28paging = True
28paging = True
29
29
30# search-url
30# search-url
31+# missing attribute: user_id, app_version, app_locale
31−url = 'https://api.soundcloud.com/'
32+url = 'https://api-v2.soundcloud.com/'
32search_url = url + 'search?{query}'\
33search_url = url + 'search?{query}'\
34+ '&variant_ids='\
33 '&facet=model'\
35 '&facet=model'\
34 '&limit=20'\
36 '&limit=20'\
35 '&offset={offset}'\
37 '&offset={offset}'\
@@ -57,7 +59,7 @@ def get_client_id():
57 # gets app_js and searches for the clientid
59 # gets app_js and searches for the clientid
58 response = http_get(app_js_url)
60 response = http_get(app_js_url)
59 if response.ok:
61 if response.ok:
60− cids = cid_re.search(response.text)
62+ cids = cid_re.search(response.content.decode("utf-8"))
61 if cids is not None and len(cids.groups()):
63 if cids is not None and len(cids.groups()):
62 return cids.groups()[0]
64 return cids.groups()[0]
63 logger.warning("Unable to fetch guest client_id from SoundCloud, check parser!")
65 logger.warning("Unable to fetch guest client_id from SoundCloud, check parser!")
searx/utils.py+15−6
@@ -47,6 +47,8 @@ blocked_tags = ('script',
47useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__))
47useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__))
48 + "/data/useragents.json", 'r', encoding='utf-8').read())
48 + "/data/useragents.json", 'r', encoding='utf-8').read())
49
49
50+lang_to_lc_cache = dict()
51+
50
52
51def searx_useragent():
53def searx_useragent():
52 return 'searx/{searx_version} {suffix}'.format(
54 return 'searx/{searx_version} {suffix}'.format(
@@ -183,7 +185,7 @@ def get_resources_directory(searx_directory, subdirectory, resources_directory):
183 if not resources_directory:
185 if not resources_directory:
184 resources_directory = os.path.join(searx_directory, subdirectory)
186 resources_directory = os.path.join(searx_directory, subdirectory)
185 if not os.path.isdir(resources_directory):
187 if not os.path.isdir(resources_directory):
186− raise Exception(directory + " is not a directory")
188+ raise Exception(resources_directory + " is not a directory")
187 return resources_directory
189 return resources_directory
188
190
189
191
@@ -314,6 +316,17 @@ def is_valid_lang(lang):
314 return False
316 return False
315
317
316
318
319+def _get_lang_to_lc_dict(lang_list):
320+ key = str(lang_list)
321+ value = lang_to_lc_cache.get(key, None)
322+ if value is None:
323+ value = dict()
324+ for lc in lang_list:
325+ value.setdefault(lc.split('-')[0], lc)
326+ lang_to_lc_cache[key] = value
327+ return value
328+
329+
317# auxiliary function to match lang_code in lang_list
330# auxiliary function to match lang_code in lang_list
318def _match_language(lang_code, lang_list=[], custom_aliases={}):
331def _match_language(lang_code, lang_list=[], custom_aliases={}):
319 # replace language code with a custom alias if necessary
332 # replace language code with a custom alias if necessary
@@ -334,11 +347,7 @@ def _match_language(lang_code, lang_list=[], custom_aliases={}):
334 return new_code
347 return new_code
335
348
336 # try to get the any supported country for this language
349 # try to get the any supported country for this language
337− for lc in lang_list:
350+ return _get_lang_to_lc_dict(lang_list).get(lang_code, None)
338− if lang_code == lc.split('-')[0]:
339− return lc
340−
341− return None
342
351
343
352
344# get the language code from lang_list that best matches locale_code
353# get the language code from lang_list that best matches locale_code