Advertisement
opexxx

torrent2magnet.py

May 22nd, 2015
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. import sys
  2. import bencode
  3. import hashlib
  4. import base64
  5. import urllib
  6.  
  7. torrent_file = sys.argv[1]
  8. torrent = open(torrent_file, 'r').read()
  9. metadata = bencode.bdecode(torrent)
  10.  
  11. hashcontents = bencode.bencode(metadata['info'])
  12. digest = hashlib.sha1(hashcontents).digest()
  13. b32hash = base64.b32encode(digest)
  14. print "magnet:?xt=urn:btih:%s" %  b32hash
  15.  
  16. params = {
  17.   'xt': 'urn:btih:%s' % b32hash,
  18.   'dn': metadata['info']['name'],
  19.   'tr': metadata['announce'],
  20.   'xl': metadata['info']['length']}
  21.  
  22. paramstr = urllib.urlencode(params)
  23. magneturi = 'magnet:?%s' % paramstr
  24. print magneturi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement