From a8064d2add6d00680669c06aaa66093302df6ec1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 5 Aug 2021 20:23:54 +0200 Subject: [PATCH] parse_magnet_uri can return either a metadata object or a dict depending on the libtorrent version --- platypush/plugins/torrent.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/platypush/plugins/torrent.py b/platypush/plugins/torrent.py index 0787d4c33..5ec289daf 100644 --- a/platypush/plugins/torrent.py +++ b/platypush/plugins/torrent.py @@ -258,13 +258,22 @@ class TorrentPlugin(Plugin): if torrent.startswith('magnet:?'): magnet = torrent magnet_info = lt.parse_magnet_uri(magnet) - info = { - 'name': magnet_info.name, - 'url': magnet, - 'magnet': magnet, - 'trackers': magnet_info.trackers, - 'save_path': download_dir, - } + if isinstance(magnet_info, dict): + info = { + 'name': magnet_info.get('name'), + 'url': magnet, + 'magnet': magnet, + 'trackers': magnet_info.get('trackers', []), + 'save_path': download_dir, + } + else: + info = { + 'name': magnet_info.name, + 'url': magnet, + 'magnet': magnet, + 'trackers': magnet_info.trackers, + 'save_path': download_dir, + } elif torrent.startswith('http://') or torrent.startswith('https://'): response = requests.get(torrent, allow_redirects=True) torrent_file = os.path.join(download_dir, self._generate_rand_filename())