aboutsummaryrefslogtreecommitdiffstats
path: root/gallery_dl/util.py
diff options
context:
space:
mode:
authorLibravatarUnit 193 <unit193@unit193.net>2021-08-13 17:45:31 -0400
committerLibravatarUnit 193 <unit193@unit193.net>2021-08-13 17:45:31 -0400
commitd50ba9cfe80f00e02ca9a4714f75699c00e67128 (patch)
tree01fe7b46370d5068b8c692ae5ea95cab4d734bd8 /gallery_dl/util.py
parent873d9a628e9412a79bdc64cd962470749de3425b (diff)
New upstream version 1.18.3.upstream/1.18.3
Diffstat (limited to 'gallery_dl/util.py')
-rw-r--r--gallery_dl/util.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/gallery_dl/util.py b/gallery_dl/util.py
index 3462138..2c0fae6 100644
--- a/gallery_dl/util.py
+++ b/gallery_dl/util.py
@@ -97,6 +97,17 @@ def generate_token(size=16):
return binascii.hexlify(data).decode()
+def format_value(value, unit="B", suffixes="kMGTPEZY"):
+ value = format(value)
+ value_len = len(value)
+ index = value_len - 4
+ if index >= 0:
+ offset = (value_len - 1) % 3 + 1
+ return (value[:offset] + "." + value[offset:offset+2] +
+ suffixes[index // 3] + unit)
+ return value + unit
+
+
def combine_dict(a, b):
"""Recursively combine the contents of 'b' into 'a'"""
for key, value in b.items():