summaryrefslogtreecommitdiff
path: root/searx/utils.py
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-02-20 10:51:58 +0100
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-02-25 16:22:37 +0100
commite76ab1a4b3a99b0ec2ef90c3aadc92ffbf6889b1 (patch)
treebe5443686fbe1ab6a6fa95e55a12a189230ba92e /searx/utils.py
parentb683aa63fb3e1689c28bd4b762b4ad962e8e232c (diff)
downloadsearxng-e76ab1a4b3a99b0ec2ef90c3aadc92ffbf6889b1.tar.gz
searxng-e76ab1a4b3a99b0ec2ef90c3aadc92ffbf6889b1.zip
[refactor] images: add resolution, image format and filesize fields
Co-authored-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/utils.py')
-rw-r--r--searx/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py
index c009c3144..b0794c244 100644
--- a/searx/utils.py
+++ b/searx/utils.py
@@ -353,6 +353,18 @@ def get_torrent_size(filesize: str, filesize_multiplier: str) -> Optional[int]:
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:
"""Convert number_str to int or 0 if number_str is not a number."""
if number_str.isdigit():