pythonvariablespython-3.xbittorrentutorrent

Python 3: Opening A Magnet Link Contained In A Variable


I have a magnet link (e.g.: magnet:?xt=urn:btih:1c1b9f5a3b6f19d8dbcbab5d5a43a6585e4a7db6) contained in a variable as a string and would like the script to open the default program that handles magnet links so that it starts downloading the torrent (like if I opened a magnet link from within my file manager).

For the sake of making answers clear we will say that we have the magnet link in a variable called magnet_link.


Solution

  • On Windows you can use os.startfile:

    os.startfile(magnet_link)
    

    For Mac/OSX you could probably use applescript and pipe it to osascript, for Linux you might be able to use xdg-open.