From 0145b95e1762e98cc3ce43e750d158a254fc9be4 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Fri, 19 Mar 2021 11:25:05 +0000 Subject: Fix handling torrents with sizes less that 1K --- tpblite/models/torrents.py | 7 +++---- 1 file 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) -- cgit v1.2.3