aboutsummaryrefslogtreecommitdiffstats
path: root/tpblite
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@fps.ee>2021-03-19 11:25:05 +0000
committerFilipp Lepalaan <filipp@fps.ee>2021-03-19 11:25:05 +0000
commit0145b95e1762e98cc3ce43e750d158a254fc9be4 (patch)
treeb25122d2aac40995387179998dbb73e093081d72 /tpblite
parent686dfbc18ac65102281b05df902d879cf769d055 (diff)
downloadtpb-lite-master.tar.gz
tpb-lite-master.tar.bz2
tpb-lite-master.zip
Fix handling torrents with sizes less that 1KHEADmaster
Diffstat (limited to 'tpblite')
-rw-r--r--tpblite/models/torrents.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/tpblite/models/torrents.py b/tpblite/models/torrents.py
index 3d6fc10..3eaee7d 100644
--- a/tpblite/models/torrents.py
+++ b/tpblite/models/torrents.py
@@ -5,11 +5,10 @@ import lxml.etree as ET
def fileSizeStrToInt(size_str):
"""Converts file size given in *iB format to bytes integer"""
- unit_dict = {"KiB": (2 ** 10), "MiB": (2 ** 20), "GiB": (2 ** 30), "TiB": (2 ** 40)}
+ unit_dict = {"B": 1, "KiB": (2 ** 10), "MiB": (2 ** 20), "GiB": (2 ** 30), "TiB": (2 ** 40)}
try:
- num = float(size_str[:-3])
- unit = size_str[-3:]
- return int(num * unit_dict[unit])
+ (num, unit) = size_str.split()
+ return int(float(num) * unit_dict[unit])
except Exception as e:
raise AttributeError(
"Cannot determine filesize: {0}, error: {1}".format(size_str, e)