INNER CODE UNIT · Python
_detect_kind
ermaozi/get_subscribe · main.py:69
def _detect_kind(text):
"""根据下载内容判断订阅类型:'clash' / 'v2ray',无法识别返回 None。"""
sample = text.strip()
if not sample:
return None
if re.search(r"^(?:proxies|proxy-groups)\s*:", sample, re.MULTILINE):
try:
data = yaml.safe_load(sample)
except yaml.YAMLError:
return None
proxies = data.get("proxies") if isinstance(data, dict) else None
if isinstance(proxies, list) and proxies and all(
isinstance(proxy, dict) and isinstance(proxy.get("name"), str) and proxy["name"]
and proxy.get("type") and proxy.get("server") for proxy in proxies
):
return "clash"
return None
decoded = sample if _NODE_SCHEME_RE.match(sample) else _b64decode(sample)