diff options
author | Bnyro <bnyro@tutanota.com> | 2024-06-12 22:35:13 +0200 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-06-15 15:42:29 +0200 |
commit | e9f8412a6e4b399a3335da73b3d321104bb0c4fb (patch) | |
tree | 0caf5c1bede7bb8739c5c2e5d107fa75455ecc24 /searx/engines/torznab.py | |
parent | 16ce5612dd0ef426b6851ab97b248595f3933d8f (diff) | |
download | searxng-e9f8412a6e4b399a3335da73b3d321104bb0c4fb.tar.gz searxng-e9f8412a6e4b399a3335da73b3d321104bb0c4fb.zip |
[perf] torrents.html, files.html: don't parse and re-format filesize
Diffstat (limited to 'searx/engines/torznab.py')
-rw-r--r-- | searx/engines/torznab.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/searx/engines/torznab.py b/searx/engines/torznab.py index 70ba78ab4..cfe7e2b4f 100644 --- a/searx/engines/torznab.py +++ b/searx/engines/torznab.py @@ -56,6 +56,7 @@ from urllib.parse import quote from lxml import etree # type: ignore from searx.exceptions import SearxEngineAPIException +from searx.utils import humanize_bytes if TYPE_CHECKING: import httpx @@ -137,11 +138,9 @@ def build_result(item: etree.Element) -> Dict[str, Any]: if enclosure is not None: enclosure_url = enclosure.get('url') - size = get_attribute(item, 'size') - if not size and enclosure: - size = enclosure.get('length') - if size: - size = int(size) + filesize = get_attribute(item, 'size') + if not filesize and enclosure: + filesize = enclosure.get('length') guid = get_attribute(item, 'guid') comments = get_attribute(item, 'comments') @@ -154,7 +153,7 @@ def build_result(item: etree.Element) -> Dict[str, Any]: result: Dict[str, Any] = { 'template': 'torrent.html', 'title': get_attribute(item, 'title'), - 'filesize': size, + 'filesize': humanize_bytes(int(filesize)) if filesize else None, 'files': get_attribute(item, 'files'), 'seed': seeders, 'leech': _map_leechers(leechers, seeders, peers), |