Skip to content

Commit

Permalink
Refactor magnet link copy function
Browse files Browse the repository at this point in the history
The function for copying the magnet link has been refactored. The code now uses a more pythonic way to filter valid URLs from trackers and handles missing keys in the current download dictionary gracefully. This change improves readability and robustness of the code.
  • Loading branch information
drew2a committed May 2, 2024
1 parent 202fc35 commit 52d9139
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/tribler/gui/widgets/downloadsdetailstabwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 52d9139

Please sign in to comment.