mirror of
https://github.com/searxng/searxng.git
synced 2026-05-26 21:00:13 +02:00
[fix] yandex images: crashes when parsing images without fallback source (#6084)
This commit is contained in:
+12
-11
@@ -87,7 +87,6 @@ def request(query, params):
|
|||||||
|
|
||||||
def response(resp):
|
def response(resp):
|
||||||
if search_type == 'web':
|
if search_type == 'web':
|
||||||
|
|
||||||
catch_bad_response(resp)
|
catch_bad_response(resp)
|
||||||
|
|
||||||
dom = html.fromstring(resp.text)
|
dom = html.fromstring(resp.text)
|
||||||
@@ -106,7 +105,6 @@ def response(resp):
|
|||||||
return results
|
return results
|
||||||
|
|
||||||
if search_type == 'images':
|
if search_type == 'images':
|
||||||
|
|
||||||
catch_bad_response(resp)
|
catch_bad_response(resp)
|
||||||
|
|
||||||
html_data = html.fromstring(resp.text)
|
html_data = html.fromstring(resp.text)
|
||||||
@@ -127,22 +125,25 @@ def response(resp):
|
|||||||
for _, item_data in json_resp['initialState']['serpList']['items']['entities'].items():
|
for _, item_data in json_resp['initialState']['serpList']['items']['entities'].items():
|
||||||
title = item_data['snippet']['title']
|
title = item_data['snippet']['title']
|
||||||
source = item_data['snippet']['url']
|
source = item_data['snippet']['url']
|
||||||
thumb = item_data['image']
|
|
||||||
fullsize_image = item_data['viewerData']['dups'][0]['url']
|
image_source = item_data["viewerData"]["thumb"]
|
||||||
height = item_data['viewerData']['dups'][0]['h']
|
for i in item_data['viewerData']['dups'] + item_data['viewerData']['preview']:
|
||||||
width = item_data['viewerData']['dups'][0]['w']
|
if i["h"] > image_source["h"]:
|
||||||
filesize = item_data['viewerData']['dups'][0]['fileSizeInBytes']
|
image_source = i
|
||||||
humanized_filesize = humanize_bytes(filesize)
|
|
||||||
|
humanized_filesize = None
|
||||||
|
if image_source.get("fileSizeInBytes"):
|
||||||
|
humanized_filesize = humanize_bytes(image_source["fileSizeInBytes"])
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
'title': title,
|
'title': title,
|
||||||
'url': source,
|
'url': source,
|
||||||
'img_src': fullsize_image,
|
'img_src': image_source["url"],
|
||||||
'filesize': humanized_filesize,
|
'filesize': humanized_filesize,
|
||||||
'thumbnail_src': thumb,
|
'thumbnail_src': item_data["image"],
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
'resolution': f'{width} x {height}',
|
'resolution': f'{image_source["w"]} x {image_source["h"]}',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user