Created
May 5, 2014 08:21
-
-
Save lsongdev/644dfee919827eb6b321 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment