parse_magnet_uri can return either a metadata object or a dict depending on the libtorrent version

This commit is contained in:
Fabio Manganiello 2021-08-05 20:23:54 +02:00
parent d086da64f6
commit a8064d2add

View file

@ -258,13 +258,22 @@ class TorrentPlugin(Plugin):
if torrent.startswith('magnet:?'): if torrent.startswith('magnet:?'):
magnet = torrent magnet = torrent
magnet_info = lt.parse_magnet_uri(magnet) magnet_info = lt.parse_magnet_uri(magnet)
info = { if isinstance(magnet_info, dict):
'name': magnet_info.name, info = {
'url': magnet, 'name': magnet_info.get('name'),
'magnet': magnet, 'url': magnet,
'trackers': magnet_info.trackers, 'magnet': magnet,
'save_path': download_dir, '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://'): elif torrent.startswith('http://') or torrent.startswith('https://'):
response = requests.get(torrent, allow_redirects=True) response = requests.get(torrent, allow_redirects=True)
torrent_file = os.path.join(download_dir, self._generate_rand_filename()) torrent_file = os.path.join(download_dir, self._generate_rand_filename())