mirror of https://github.com/searxng/searxng.git
[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
|
@ -271,22 +271,54 @@ type.
|
||||||
``images``
|
``images``
|
||||||
----------
|
----------
|
||||||
|
|
||||||
.. table:: Parameter of the **images** media type:
|
.. list-table:: Parameter of the **images** media type
|
||||||
|
:header-rows: 2
|
||||||
:width: 100%
|
:width: 100%
|
||||||
|
|
||||||
========================= =====================================================
|
* - result-parameter
|
||||||
result-parameter information
|
- Python type
|
||||||
------------------------- -----------------------------------------------------
|
- information
|
||||||
template is set to ``images.html``
|
|
||||||
========================= =====================================================
|
* - template
|
||||||
url string, url to the result site
|
- :py:class:`str`
|
||||||
title string, title of the result *(partly implemented)*
|
- is set to ``images.html``
|
||||||
content *(partly implemented)*
|
|
||||||
publishedDate :py:class:`datetime.datetime`,
|
* - url
|
||||||
time of publish *(partly implemented)*
|
- :py:class:`str`
|
||||||
img\_src string, url to the result image
|
- url to the result site
|
||||||
thumbnail\_src string, url to a small-preview image
|
|
||||||
========================= =====================================================
|
* - title
|
||||||
|
- :py:class:`str`
|
||||||
|
- title of the result
|
||||||
|
|
||||||
|
* - content
|
||||||
|
- :py:class:`str`
|
||||||
|
- description of the image
|
||||||
|
|
||||||
|
* - publishedDate
|
||||||
|
- :py:class:`datetime <datetime.datetime>`
|
||||||
|
- time of publish
|
||||||
|
|
||||||
|
* - img_src
|
||||||
|
- :py:class:`str`
|
||||||
|
- url to the result image
|
||||||
|
|
||||||
|
* - thumbnail_src
|
||||||
|
- :py:class:`str`
|
||||||
|
- url to a small-preview image
|
||||||
|
|
||||||
|
* - resolution
|
||||||
|
- :py:class:`str`
|
||||||
|
- the resolution of the image (e.g. ``1920 x 1080`` pixel)
|
||||||
|
|
||||||
|
* - img_format
|
||||||
|
- :py:class:`str`
|
||||||
|
- the format of the image (e.g. ``png``)
|
||||||
|
|
||||||
|
* - filesize
|
||||||
|
- :py:class:`str`
|
||||||
|
- size of bytes in :py:obj:`human readable <searx.humanize_bytes>` notation
|
||||||
|
(e.g. ``MB`` for 1024 \* 1024 Bytes filesize).
|
||||||
|
|
||||||
|
|
||||||
.. _template videos:
|
.. _template videos:
|
||||||
|
|
|
@ -58,10 +58,9 @@ def response(resp):
|
||||||
{
|
{
|
||||||
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
||||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||||
'content': result['medium_display'],
|
'content': "%(medium_display)s // %(dimensions)s" % result,
|
||||||
'author': ', '.join(result['artist_titles']),
|
'author': ', '.join(result['artist_titles']),
|
||||||
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
||||||
'img_format': result['dimensions'],
|
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -92,7 +92,7 @@ def response(resp):
|
||||||
|
|
||||||
metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
|
metadata = json.loads(result.xpath('.//a[@class="iusc"]/@m')[0])
|
||||||
title = ' '.join(result.xpath('.//div[@class="infnmpt"]//a/text()')).strip()
|
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()
|
source = ' '.join(result.xpath('.//div[@class="imgpt"]//div[@class="lnkw"]//a/text()')).strip()
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,8 @@ def response(resp):
|
||||||
'content': metadata['desc'],
|
'content': metadata['desc'],
|
||||||
'title': title,
|
'title': title,
|
||||||
'source': source,
|
'source': source,
|
||||||
'img_format': img_format,
|
'resolution': img_format[0],
|
||||||
|
'img_format': img_format[1] if len(img_format) >= 2 else None,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return results
|
return results
|
||||||
|
|
|
@ -367,9 +367,10 @@ def _parse_images(json_resp):
|
||||||
'title': result['title'],
|
'title': result['title'],
|
||||||
'content': result['description'],
|
'content': result['description'],
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
'img_format': result['properties']['format'],
|
'resolution': result['properties']['format'],
|
||||||
'source': result['source'],
|
'source': result['source'],
|
||||||
'img_src': result['properties']['url'],
|
'img_src': result['properties']['url'],
|
||||||
|
'thumbnail_src': result['thumbnail']['src'],
|
||||||
}
|
}
|
||||||
result_list.append(item)
|
result_list.append(item)
|
||||||
|
|
||||||
|
|
|
@ -89,10 +89,9 @@ def response(resp):
|
||||||
{
|
{
|
||||||
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
'url': 'https://artic.edu/artworks/%(id)s' % result,
|
||||||
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
'title': result['title'] + " (%(date_display)s) // %(artist_display)s" % result,
|
||||||
'content': result['medium_display'],
|
'content': "%(medium_display)s // %(dimensions)s" % result,
|
||||||
'author': ', '.join(result['artist_titles']),
|
'author': ', '.join(result['artist_titles']),
|
||||||
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
'img_src': image_api + '/%(image_id)s/full/843,/0/default.jpg' % result,
|
||||||
'img_format': result['dimensions'],
|
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -96,7 +96,7 @@ def _image_result(result):
|
||||||
'content': '',
|
'content': '',
|
||||||
'thumbnail_src': result['thumbnail'],
|
'thumbnail_src': result['thumbnail'],
|
||||||
'img_src': result['image'],
|
'img_src': result['image'],
|
||||||
'img_format': '%s x %s' % (result['width'], result['height']),
|
'resolution': '%s x %s' % (result['width'], result['height']),
|
||||||
'source': result['source'],
|
'source': result['source'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ def response(resp): # pylint: disable=too-many-branches
|
||||||
continue
|
continue
|
||||||
|
|
||||||
img_src = size_data['url']
|
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
|
# For a bigger thumbnail, keep only the url_z, not the url_n
|
||||||
if 'n' in photo['sizes']['data']:
|
if 'n' in photo['sizes']['data']:
|
||||||
|
@ -131,7 +131,7 @@ def response(resp): # pylint: disable=too-many-branches
|
||||||
'img_src': img_src,
|
'img_src': img_src,
|
||||||
'thumbnail_src': thumbnail_src,
|
'thumbnail_src': thumbnail_src,
|
||||||
'source': source,
|
'source': source,
|
||||||
'img_format': img_format,
|
'resolution': resolution,
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
}
|
}
|
||||||
result['author'] = author.encode(errors='ignore').decode()
|
result['author'] = author.encode(errors='ignore').decode()
|
||||||
|
|
|
@ -103,7 +103,7 @@ def response(resp):
|
||||||
'title': item["result"]["page_title"],
|
'title': item["result"]["page_title"],
|
||||||
'content': item["text_in_grid"]["snippet"],
|
'content': item["text_in_grid"]["snippet"],
|
||||||
'source': item["result"]["site_title"],
|
'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"],
|
'img_src': item["original_image"]["url"],
|
||||||
'thumbnail_src': item["thumbnail"]["url"],
|
'thumbnail_src': item["thumbnail"]["url"],
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
|
|
|
@ -265,6 +265,8 @@ def parse_web_api(resp):
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
'thumbnail_src': thumbnail,
|
'thumbnail_src': thumbnail,
|
||||||
'img_src': img_src,
|
'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'],
|
'url': summary['refererurl'],
|
||||||
'title': result['title'],
|
'title': result['title'],
|
||||||
'img_src': result['url'],
|
'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'],
|
'thumbnail_src': 'https://media.seekr.com/engine/rp/' + summary['tg'] + '/?src= ' + result['thumbnail'],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib.parse import urlencode
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
|
from searx.utils import humanize_bytes
|
||||||
|
|
||||||
about = {
|
about = {
|
||||||
'website': 'https://wallhaven.cc/',
|
'website': 'https://wallhaven.cc/',
|
||||||
'official_api_documentation': 'https://wallhaven.cc/help/api',
|
'official_api_documentation': 'https://wallhaven.cc/help/api',
|
||||||
|
@ -68,6 +70,7 @@ def response(resp):
|
||||||
json = resp.json()
|
json = resp.json()
|
||||||
|
|
||||||
for result in json['data']:
|
for result in json['data']:
|
||||||
|
|
||||||
results.append(
|
results.append(
|
||||||
{
|
{
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
|
@ -76,8 +79,10 @@ def response(resp):
|
||||||
'url': result['url'],
|
'url': result['url'],
|
||||||
'img_src': result['path'],
|
'img_src': result['path'],
|
||||||
'thumbnail_src': result['thumbs']['small'],
|
'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'),
|
'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,
|
'title': title,
|
||||||
'content': item["snippet"],
|
'content': item["snippet"],
|
||||||
'img_src': imageinfo["url"],
|
'img_src': imageinfo["url"],
|
||||||
'img_format': f'{imageinfo["width"]} x {imageinfo["height"]}',
|
'resolution': f'{imageinfo["width"]} x {imageinfo["height"]}',
|
||||||
'thumbnail_src': imageinfo["thumburl"],
|
'thumbnail_src': imageinfo["thumburl"],
|
||||||
'template': 'images.html',
|
'template': 'images.html',
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,7 @@ article.result-images .detail {
|
||||||
|
|
||||||
.result-images-labels {
|
.result-images-labels {
|
||||||
color: var(--color-result-detail-font);
|
color: var(--color-result-detail-font);
|
||||||
max-height: 16rem;
|
height: 19rem;
|
||||||
min-height: 16rem;
|
|
||||||
|
|
||||||
hr {
|
hr {
|
||||||
border-top: 1px solid var(--color-result-detail-hr);
|
border-top: 1px solid var(--color-result-detail-hr);
|
||||||
|
@ -62,11 +61,13 @@ article.result-images .detail {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
color: var(--color-result-detail-label-font);
|
color: var(--color-result-detail-label-font);
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
|
line-height: 0.9rem;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -82,6 +83,7 @@ article.result-images .detail {
|
||||||
|
|
||||||
p.result-content {
|
p.result-content {
|
||||||
height: 2rem;
|
height: 2rem;
|
||||||
|
line-height: unset;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
<a {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} href="{{ result.img_src }}">{{- "" -}}
|
<a {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} href="{{ result.img_src }}">{{- "" -}}
|
||||||
<img class="image_thumbnail" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} src="{% if result.thumbnail_src %}{{ image_proxify(result.thumbnail_src) }}{% else %}{{ image_proxify(result.img_src) }}{% endif %}" alt="{{ result.title|striptags }}" loading="lazy" width="200" height="200">{{- "" -}}
|
<img class="image_thumbnail" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} src="{% if result.thumbnail_src %}{{ image_proxify(result.thumbnail_src) }}{% else %}{{ image_proxify(result.img_src) }}{% endif %}" alt="{{ result.title|striptags }}" loading="lazy" width="200" height="200">{{- "" -}}
|
||||||
<span class="title">{{ result.title|striptags }}</span>{{- "" -}}
|
<span class="title">{{ result.title|striptags }}</span>{{- "" -}}
|
||||||
<span class="source">{{ result.parsed_url.netloc }}</span>{{- "" -}}
|
<span class="source">
|
||||||
|
{{- result.parsed_url.netloc -}}
|
||||||
|
{%- if result.resolution %} - {{ result.resolution }}{%- endif -%}
|
||||||
|
</span>{{- "" -}}
|
||||||
</a>{{- "" -}}
|
</a>{{- "" -}}
|
||||||
<div class="detail">{{- "" -}}
|
<div class="detail">{{- "" -}}
|
||||||
<a class="result-detail-close" href="#">{{ icon('close') }}</a>{{- "" -}}
|
<a class="result-detail-close" href="#">{{ icon('close') }}</a>{{- "" -}}
|
||||||
|
@ -16,7 +19,9 @@
|
||||||
<p class="result-content">{%- if result.content %}{{ result.content|striptags }}{% else %} {% endif -%}</p>{{- "" -}}
|
<p class="result-content">{%- if result.content %}{{ result.content|striptags }}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
<hr>{{- "" -}}
|
<hr>{{- "" -}}
|
||||||
<p class="result-author">{%- if result.author %}<span>{{ _('Author') }}:</span>{{ result.author|striptags }}{% else %} {% endif -%}</p>{{- "" -}}
|
<p class="result-author">{%- if result.author %}<span>{{ _('Author') }}:</span>{{ result.author|striptags }}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
|
<p class="result-resolution">{%- if result.resolution %}<span>{{ _('Resolution') }}:</span>{{ result.resolution }}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
<p class="result-format">{%- if result.img_format %}<span>{{ _('Format') }}:</span>{{ result.img_format }}{% else %} {% endif -%}</p>{{- "" -}}
|
<p class="result-format">{%- if result.img_format %}<span>{{ _('Format') }}:</span>{{ result.img_format }}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
|
<p class="result-filesize">{%- if result.filesize %}<span>{{ _('Filesize') }}:</span>{{ result.filesize}}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
<p class="result-source">{%- if result.source %}<span>{{ _('Source') }}:</span>{{ result.source }}{% else %} {% endif -%}</p>{{- "" -}}
|
<p class="result-source">{%- if result.source %}<span>{{ _('Source') }}:</span>{{ result.source }}{% else %} {% endif -%}</p>{{- "" -}}
|
||||||
<p class="result-engine"><span>{{ _('Engine') }}:</span>{{ result.engine }}</p>{{- "" -}}{{- "" -}}
|
<p class="result-engine"><span>{{ _('Engine') }}:</span>{{ result.engine }}</p>{{- "" -}}{{- "" -}}
|
||||||
<p class="result-url"><span>{{ _('View source') }}:</span><a {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} href="{{ result.url }}">{{ result.url }}</a></p>{{- "" -}}
|
<p class="result-url"><span>{{ _('View source') }}:</span><a {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %} href="{{ result.url }}">{{ result.url }}</a></p>{{- "" -}}
|
||||||
|
|
|
@ -353,6 +353,18 @@ def get_torrent_size(filesize: str, filesize_multiplier: str) -> Optional[int]:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def humanize_bytes(size, precision=2):
|
||||||
|
"""Determine the *human readable* value of bytes on 1024 base (1KB=1024B)."""
|
||||||
|
s = ['B ', 'KB', 'MB', 'GB', 'TB']
|
||||||
|
|
||||||
|
x = len(s)
|
||||||
|
p = 0
|
||||||
|
while size > 1024 and p < x:
|
||||||
|
p += 1
|
||||||
|
size = size / 1024.0
|
||||||
|
return "%.*f %s" % (precision, size, s[p])
|
||||||
|
|
||||||
|
|
||||||
def convert_str_to_int(number_str: str) -> int:
|
def convert_str_to_int(number_str: str) -> int:
|
||||||
"""Convert number_str to int or 0 if number_str is not a number."""
|
"""Convert number_str to int or 0 if number_str is not a number."""
|
||||||
if number_str.isdigit():
|
if number_str.isdigit():
|
||||||
|
|
Loading…
Reference in New Issue