diff --git a/src/aria2p/downloads.py b/src/aria2p/downloads.py index 1dc5b54..fc02d52 100644 --- a/src/aria2p/downloads.py +++ b/src/aria2p/downloads.py @@ -638,7 +638,7 @@ def bittorrent(self): BitTorrent only. """ - if not self._bittorrent: + if not self._bittorrent and "bittorrent" in self._struct: self._bittorrent = BitTorrent(self._struct.get("bittorrent")) return self._bittorrent diff --git a/tests/test_downloads.py b/tests/test_downloads.py index c56f1b1..07b782c 100644 --- a/tests/test_downloads.py +++ b/tests/test_downloads.py @@ -119,6 +119,11 @@ def test_bittorrent(self): self.download._struct["bittorrent"] = {"mode": "single"} assert self.download.bittorrent.mode is None + # assert is None when "bittorrent" key is not in struct + del self.download._struct["bittorrent"] + self.download._bittorrent = None + assert self.download.bittorrent is None + def test_completed_length(self): assert self.download.completed_length == 889_592_532