Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import bencode
- import hashlib
- import base64
- import urllib
- torrent_file = sys.argv[1]
- torrent = open(torrent_file, 'r').read()
- metadata = bencode.bdecode(torrent)
- hashcontents = bencode.bencode(metadata['info'])
- digest = hashlib.sha1(hashcontents).digest()
- b32hash = base64.b32encode(digest)
- print "magnet:?xt=urn:btih:%s" % b32hash
- params = {
- 'xt': 'urn:btih:%s' % b32hash,
- 'dn': metadata['info']['name'],
- 'tr': metadata['announce'],
- 'xl': metadata['info']['length']}
- paramstr = urllib.urlencode(params)
- magneturi = 'magnet:?%s' % paramstr
- print magneturi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement