code: def make_magnet_meta(self, magnet_uri):
          
          import cgi
          import hashlib
  
          if magnet_uri.startswith("magnet:"):
              magnet_uri = magnet_uri[7:]
          meta = {"magnet-uri": "magnet:" + magnet_uri}
          magnet_params = cgi.parse_qs(magnet_uri.lstrip('?'))
  
          meta_name = magnet_params.get("xt", [hashlib.sha1(magnet_uri).hexdigest()])[0]
          if "dn" in magnet_params:
              meta_name = "%s-%s" % (magnet_params["dn"][0], meta_name)
          meta_name = re.sub(r"[^-_,a-zA-Z0-9]+", '.', meta_name).strip('.').replace("urn.btih.", "")
  
          if not config.magnet_watch:
              self.fatal("You MUST set the 'magnet_watch' config option!")
          meta_path = os.path.join(config.magnet_watch, "magnet-%s.torrent" % meta_name)
          self.LOG.debug("Writing magnet-uri metafile %r..." % (meta_path,))
  
          try:
              bencode.bwrite(meta_path, meta)
          except EnvironmentError as exc:
              self.fatal("Error writing magnet-uri metafile %r (%s)" % (meta_path, exc,))
              raise
docs: Create a magnet-uri torrent.