Saving magnet links as torrent files in kde
$ cat .kde/share/kde4/services/magnet.protocol
1 2 3 4 5 6 7 8 9 10 11 |
[Protocol] exec=/path/to/magnet2torrent.py "%u" protocol=magnet input=none output=none helper=true listing=false reading=false writing=false makedir=false deleting=false |
$ cat bin/magnet2torrent.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#!/usr/bin/python import os import sys def torrent_name(magnet): for i in magnet.split('&'): if i.startswith('dn='): return i + ".torrent" return magnet.replace(':', '-') + ".torrent" if len(sys.argv) != 2: print >> sys.stderr, "Usage: %s <magnet url>" % sys.argv[0] sys.exit(1) magnet = sys.argv[1] torrent = "d10:magnet-uri" + str(len(magnet)) + ":" + magnet + "e" f = open(os.path.expanduser("~/test/%s" % torrent_name(magnet)), 'w') f.write(torrent) f.close() $ </magnet> |