# Matt Croydon http://postneo.com # Requires bencode from the bittorrent dist, this file is therefore released under the MIT license.MAXLINES # Bdecode and BitTorrent were written by Bram Cohen. Praise Bram! import bencode import sys, httplib, urlparse if len(sys.argv) == 1: # User did not provide any command line arguments print 'Usage: %s url.\nExample: %s http://url.com/file.torrent' %(sys.argv[0], sys.argv[0]) else: # Parse the given URL with urlparse url = urlparse.urlparse(sys.argv[1]) # Connect to the resource print 'Connecting to %s' % sys.argv[1] connection = httplib.HTTPConnection(url[1]) connection.request('GET', url[2]) # Get the response and prepare it for reading by bdecode response = connection.getresponse() if response.reason == 'OK': # File is correct, let's grab it data = response.read() # Decode the data torrent = bencode.bdecode(data) # Print out the information print 'Announce: %s' % torrent['announce'] print 'Name: %s' % torrent['info']['name'] print 'Piece length: %s' % torrent['info']['piece length'] print 'File Info:' for file in torrent['info']['files']: print '\tPath: %s' % file['path'] print '\tLength: %s' % file['length'] else: # Something might have gone wrong print 'Error: %s %s' % (response.status, response.reason) connection.close()