diff options
author | Filipp Lepalaan <filipp@fps.ee> | 2021-03-19 11:25:05 +0000 |
---|---|---|
committer | Filipp Lepalaan <filipp@fps.ee> | 2021-03-19 11:25:05 +0000 |
commit | 0145b95e1762e98cc3ce43e750d158a254fc9be4 (patch) | |
tree | b25122d2aac40995387179998dbb73e093081d72 /tpblite | |
parent | 686dfbc18ac65102281b05df902d879cf769d055 (diff) | |
download | tpb-lite-master.tar.gz tpb-lite-master.tar.bz2 tpb-lite-master.zip |
Diffstat (limited to 'tpblite')
-rw-r--r-- | tpblite/models/torrents.py | 7 |
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) |