1. #!/usr/bin/env python
  2. # Blizzard Downloader torrent extractor
  3.  
  4. __author__ = 'sublimal'
  5. __copyright__ =' Copyright 2007 sublimal'
  6. __version__ = '1.0'
  7. __date__ = '22-07-2007'
  8. __license__ = 'GPL'
  9.  
  10. import os, re, struct
  11.  
  12. def get_torrent_by_signature(data):
  13.     signature = data[-8:]
  14.     sig, t_size = struct.unpack('4si', signature)
  15.     assert sig == 'PSER', 'Could not find signature'
  16.     torrent = data[t_size-8:-8]
  17.     return torrent
  18.  
  19. if __name__ == '__main__':
  20.     for fname in os.listdir('.'):
  21.         if re.search('-downloader.exe$', fname):
  22.             tname = re.sub('-downloader.exe$', '.torrent', fname)
  23.             try:
  24.                 fdata = open(fname).read()
  25.                 tdata = get_torrent_by_signature(fdata)
  26.                 f = open(tname, 'wb')
  27.                 f.write(tdata)
  28.                 f.close()
  29.                 print "Extracted torrent from '%s' to '%s'" % (fname, tname)
  30.             except Exception, e:
  31.                 print "Could not extract torrent from '%s': %s" % (fname, e)
  32.  
  33.