code: def map_announce2alias(url):
      
      import urlparse
  
      # Try to find an exact alias URL match and return its label
      for alias, urls in announce.items():
          if any(i == url for i in urls):
              return alias
  
      # Try to find an alias URL prefix and return its label
      parts = urlparse.urlparse(url)
      server = urlparse.urlunparse((parts.scheme, parts.netloc, "/", None, None, None))
  
      for alias, urls in announce.items():
          if any(i.startswith(server) for i in urls):
              return alias
  
      # Return 2nd level domain name if no alias found
      try:
          return '.'.join(parts.netloc.split(':')[0].split('.')[-2:])
      except IndexError:
          return parts.netloc
docs: Get tracker alias for announce URL, and if none is defined, the 2nd level domain.