diff --git a/src/tribler/gui/widgets/downloadsdetailstabwidget.py b/src/tribler/gui/widgets/downloadsdetailstabwidget.py index 665f74f56c8..663a8a09f08 100644 --- a/src/tribler/gui/widgets/downloadsdetailstabwidget.py +++ b/src/tribler/gui/widgets/downloadsdetailstabwidget.py @@ -198,12 +198,17 @@ def update_pages(self, new_download=False): item = QTreeWidgetItem(self.window().download_peers_list) DownloadsDetailsTabWidget.update_peer_row(item, peer) - def on_copy_magnet_clicked(self, checked): - trackers = [ - tk['url'] for tk in self.current_download['trackers'] if 'url' in tk and tk['url'] not in ['[DHT]', '[PeX]'] - ] + def on_copy_magnet_clicked(self, _): + """ Copy the magnet link of the current download to the clipboard.""" + invalid_urls = {'[DHT]', '[PeX]'} + trackers = self.current_download.get('trackers', []) + urls = (t.get('url') for t in trackers) + valid_urls = [u for u in urls if u not in invalid_urls] + magnet_link = compose_magnetlink( - self.current_download['infohash'], name=self.current_download.get('name', None), trackers=trackers + infohash=self.current_download.get('infohash'), + name=self.current_download.get('name'), + trackers=valid_urls ) copy_to_clipboard(magnet_link) self.window().tray_show_message(tr("Copying magnet link"), magnet_link)