docs: def parse_torrent_buffer(torrent):
      """parse a torrent buffer"""
      md = {}
      try:
          metadata = bencode.bdecode(torrent)
      except bencode.BTL.BTFailure:
          print 'Not a valid encoded torrent'
          return None
      if 'announce-list' in metadata:
          md['trackers'] = []
          for tracker in metadata['announce-list']:
              md['trackers'].append(tracker[0])
      if 'announce' in metadata:
          md['trackers'].append(metadata['announce'])
      md['trackers'] = list(set(md['trackers']))
      if 'name' in metadata['info']:
          md['name'] = metadata['info']['name']
      webseeds = []
      if 'httpseeds' in metadata:
          webseeds = metadata['httpseeds']
      if 'url-list' in metadata:
          webseeds += md['url-list']
      if webseeds:
          md['webseeds'] = webseeds
      if 'created by' in metadata:
          md['creator'] = metadata['created by']
      if 'creation date' in metadata:
          utc_dt = datetime.utcfromtimestamp(metadata['creation date'])
          md['created'] = utc_dt.strftime('%Y-%m-%d %H:%M:%S')
      if 'comment' in metadata:
          md['comment'] = metadata['comment']
      md['piece_size'] = metadata['info']['piece length']
      if 'length' in metadata['info']:
          md['file'] = {'path': metadata['info']['name'],
                        'length': metadata['info']['length']}
      if 'files' in metadata['info']:
          md['files'] = []
          for item in metadata['info']['files']:
              md['files'].append(
                  {'path': item['path'][0], 'length': item['length']})
      # TODO check if torrent is private and encoding
      hashcontents = bencode.bencode(metadata['info'])
      digest = hashlib.sha1(hashcontents).digest()
      md['infoHash'] = hashlib.sha1(hashcontents).hexdigest()
      b32hash = base64.b32encode(digest)
      md['infoHash_b32'] = b32hash
      md['pieces'] = _split_pieces(metadata['info']['pieces'])
      md['total_size'] = hsize(sum([x['length'] for x in md['files']]))
      return md