forked from Icycoide/searxng
[refactor] images: add resolution, image format and filesize fields
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
This commit is contained in:
parent
b683aa63fb
commit
e76ab1a4b3
15 changed files with 91 additions and 33 deletions
|
@ -57,11 +57,10 @@ def response(resp):
|
|||
results.append(
|
||||
{
|
||||
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||
'content': result['medium_display'],
|
||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||
'content': "%(medium_display)s // %(dimensions)s" % result,
|
||||
'author': ', '.join(result['artist_titles']),
|
||||
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
||||
'img_format': result['dimensions'],
|
||||
'template': 'images.html',
|
||||
}
|
||||
)
|
||||
|
|
|
@ -92,7 +92,7 @@ def response(resp):
|
|||
|
||||
metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
|
||||
title = ' '.join(result.xpath('.//div[@class="infnmpt"]//a/text()')).strip()
|
||||
img_format = ' '.join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip()
|
||||
img_format = ' '.join(result.xpath('.//div[@class="imgpt"]/div/span/text()')).strip().split(" · ")
|
||||
source = ' '.join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()
|
||||
results.append(
|
||||
{
|
||||
|
@ -103,7 +103,8 @@ def response(resp):
|
|||
'content': metadata['desc'],
|
||||
'title': title,
|
||||
'source': source,
|
||||
'img_format': img_format,
|
||||
'resolution': img_format[0],
|
||||
'img_format': img_format[1] if len(img_format) >= 2 else None,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
|
|
@ -367,9 +367,10 @@ def _parse_images(json_resp):
|
|||
'title': result['title'],
|
||||
'content': result['description'],
|
||||
'template': 'images.html',
|
||||
'img_format': result['properties']['format'],
|
||||
'resolution': result['properties']['format'],
|
||||
'source': result['source'],
|
||||
'img_src': result['properties']['url'],
|
||||
'thumbnail_src': result['thumbnail']['src'],
|
||||
}
|
||||
result_list.append(item)
|
||||
|
||||
|
|
|
@ -88,11 +88,10 @@ def response(resp):
|
|||
results.append(
|
||||
{
|
||||
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||
'content': result['medium_display'],
|
||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||
'content': "%(medium_display)s // %(dimensions)s" % result,
|
||||
'author': ', '.join(result['artist_titles']),
|
||||
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
||||
'img_format': result['dimensions'],
|
||||
'template': 'images.html',
|
||||
}
|
||||
)
|
||||
|
|
|
@ -96,7 +96,7 @@ def _image_result(result):
|
|||
'content': '',
|
||||
'thumbnail_src': result['thumbnail'],
|
||||
'img_src': result['image'],
|
||||
'img_format': '%s x %s' % (result['width'], result['height']),
|
||||
'resolution': '%s x %s' % (result['width'], result['height']),
|
||||
'source': result['source'],
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ def response(resp): # pylint: disable=too-many-branches
|
|||
continue
|
||||
|
||||
img_src = size_data['url']
|
||||
img_format = f"{size_data['width']} x {size_data['height']}"
|
||||
resolution = f"{size_data['width']} x {size_data['height']}"
|
||||
|
||||
# For a bigger thumbnail, keep only the url_z, not the url_n
|
||||
if 'n' in photo['sizes']['data']:
|
||||
|
@ -131,7 +131,7 @@ def response(resp): # pylint: disable=too-many-branches
|
|||
'img_src': img_src,
|
||||
'thumbnail_src': thumbnail_src,
|
||||
'source': source,
|
||||
'img_format': img_format,
|
||||
'resolution': resolution,
|
||||
'template': 'images.html',
|
||||
}
|
||||
result['author'] = author.encode(errors='ignore').decode()
|
||||
|
|
|
@ -103,7 +103,7 @@ def response(resp):
|
|||
'title': item["result"]["page_title"],
|
||||
'content': item["text_in_grid"]["snippet"],
|
||||
'source': item["result"]["site_title"],
|
||||
'img_format': f'{item["original_image"]["width"]} x {item["original_image"]["height"]}',
|
||||
'resolution': f'{item["original_image"]["width"]} x {item["original_image"]["height"]}',
|
||||
'img_src': item["original_image"]["url"],
|
||||
'thumbnail_src': item["thumbnail"]["url"],
|
||||
'template': 'images.html',
|
||||
|
|
|
@ -265,6 +265,8 @@ def parse_web_api(resp):
|
|||
'template': 'images.html',
|
||||
'thumbnail_src': thumbnail,
|
||||
'img_src': img_src,
|
||||
'resolution': f"{item['width']} x {item['height']}",
|
||||
'img_format': item.get('thumb_type'),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ def _images_response(json):
|
|||
'url': summary['refererurl'],
|
||||
'title': result['title'],
|
||||
'img_src': result['url'],
|
||||
'img_format': f"{summary['width']}x{summary['height']}",
|
||||
'resolution': f"{summary['width']}x{summary['height']}",
|
||||
'thumbnail_src': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
|
||||
}
|
||||
)
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
from datetime import datetime
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from searx.utils import humanize_bytes
|
||||
|
||||
about = {
|
||||
'website': 'https://wallhaven.cc/',
|
||||
'official_api_documentation': 'https://wallhaven.cc/help/api',
|
||||
|
@ -68,6 +70,7 @@ def response(resp):
|
|||
json = resp.json()
|
||||
|
||||
for result in json['data']:
|
||||
|
||||
results.append(
|
||||
{
|
||||
'template': 'images.html',
|
||||
|
@ -76,8 +79,10 @@ def response(resp):
|
|||
'url': result['url'],
|
||||
'img_src': result['path'],
|
||||
'thumbnail_src': result['thumbs']['small'],
|
||||
'img_format': result['resolution'],
|
||||
'resolution': result['resolution'].replace('x', ' x '),
|
||||
'publishedDate': datetime.strptime(result['created_at'], '%Y-%m-%d %H:%M:%S'),
|
||||
'img_format': result['file_type'],
|
||||
'filesize': humanize_bytes(result['file_size']),
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ def response(resp):
|
|||
'title': title,
|
||||
'content': item["snippet"],
|
||||
'img_src': imageinfo["url"],
|
||||
'img_format': f'{imageinfo["width"]} x {imageinfo["height"]}',
|
||||
'resolution': f'{imageinfo["width"]} x {imageinfo["height"]}',
|
||||
'thumbnail_src': imageinfo["thumburl"],
|
||||
'template': 'images.html',
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue