Files
pokemon/scripts/update_swarm/hosts.py
T

31 lines
1.2 KiB
Python

from __future__ import annotations
from urllib.parse import urlparse
def classify_url(url: str) -> tuple[str, str]:
p = urlparse(url or "")
host = (p.netloc or "").lower().removeprefix("www.")
path = p.path or ""
if host in ("github.com", "raw.githubusercontent.com", "objects.githubusercontent.com"):
if host != "github.com" or "/releases/download/" in path:
return "github", "ungated"
return "github", "gated"
if host.endswith("archive.org"):
return "archive", "ungated"
if host.endswith("mediafire.com"):
return "mediafire", "ungated"
if host.endswith("mega.nz") or host.endswith("mega.co.nz"):
return "mega", "ungated" if p.fragment else "gated"
if host.endswith("itch.io"):
return "itch", "gated"
if host in ("drive.google.com", "docs.google.com"):
return "drive", "gated"
if host in ("discord.com", "discord.gg"):
return "discord", "gated"
if host.endswith("ko-fi.com"):
return "kofi", "gated"
if host.endswith("hackdex.app"):
return "hackdex", "gated"
if host.endswith("pokecommunity.com"):
return "pokecommunity", "gated"
return "other", "gated"