From 6f8d2ce939e93e8e1fc7570659d9570fc8715ea0 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Tue, 2 Aug 2022 17:25:54 +0800 Subject: [PATCH] update: compatible decoder --- ProxyDecoder/Brook.py | 4 ++-- ProxyDecoder/Shadowsocks.py | 4 ++-- ProxyDecoder/ShadowsocksR.py | 10 ++++++++-- ProxyDecoder/Trojan.py | 4 ++-- ProxyDecoder/TrojanGo.py | 4 ++-- ProxyDecoder/VLESS.py | 4 ++-- ProxyDecoder/VMess.py | 4 ++-- ProxyDecoder/__init__.py | 2 ++ ProxyDecoder/decoder.py | 2 +- 9 files changed, 23 insertions(+), 15 deletions(-) diff --git a/ProxyDecoder/Brook.py b/ProxyDecoder/Brook.py index 15c038c..6d0c5e2 100644 --- a/ProxyDecoder/Brook.py +++ b/ProxyDecoder/Brook.py @@ -81,6 +81,6 @@ def decode(url: str) -> dict: if url.split('://')[0] != 'brook': raise Exception('Unexpected scheme') return { - **{'type': 'brook'}, - **__brookDecode(url) + 'type': 'brook', + 'info': __brookDecode(url), } diff --git a/ProxyDecoder/Shadowsocks.py b/ProxyDecoder/Shadowsocks.py index a75edd7..e9f5693 100644 --- a/ProxyDecoder/Shadowsocks.py +++ b/ProxyDecoder/Shadowsocks.py @@ -137,6 +137,6 @@ def decode(url: str, compatible: bool = False) -> dict or None: if compatible and 'remark' in ssInfo: # 向后兼容部分客户端 ssInfo['remark'] = ssInfo['remark'].replace('+', ' ') return { - **{'type': 'ss'}, - **ssInfo + 'type': 'ss', + 'info': ssInfo, } diff --git a/ProxyDecoder/ShadowsocksR.py b/ProxyDecoder/ShadowsocksR.py index bc8362b..0bf1dfd 100644 --- a/ProxyDecoder/ShadowsocksR.py +++ b/ProxyDecoder/ShadowsocksR.py @@ -44,7 +44,13 @@ def __ssrDecode(url: str) -> dict: # SSR分享链接解码 def decode(url: str) -> dict: if url.split('://')[0] != 'ssr': raise Exception('Unexpected scheme') + ssrObject = __ssrDecode(url) + group = '' + if 'group' in ssrObject: + group = ssrObject['group'] + ssrObject.pop('group') return { - **{'type': 'ssr'}, - **__ssrDecode(url) + 'type': 'ssr', + 'group': group, + 'info': ssrObject, } diff --git a/ProxyDecoder/Trojan.py b/ProxyDecoder/Trojan.py index 3d1f669..1091137 100644 --- a/ProxyDecoder/Trojan.py +++ b/ProxyDecoder/Trojan.py @@ -129,6 +129,6 @@ def decode(url: str) -> dict: if url.split('://')[0] != 'trojan': raise Exception('Unexpected scheme') return { - **{'type': 'trojan'}, - **__trojanDecode(url) + 'type': 'trojan', + 'info': __trojanDecode(url), } diff --git a/ProxyDecoder/TrojanGo.py b/ProxyDecoder/TrojanGo.py index 20bf574..237c20d 100644 --- a/ProxyDecoder/TrojanGo.py +++ b/ProxyDecoder/TrojanGo.py @@ -77,6 +77,6 @@ def decode(url: str) -> dict: if url.split('://')[0] != 'trojan-go': raise Exception('Unexpected scheme') return { - **{'type': 'trojan-go'}, - **__trojanGoDecode(url) + 'type': 'trojan-go', + 'info': __trojanGoDecode(url), } diff --git a/ProxyDecoder/VLESS.py b/ProxyDecoder/VLESS.py index 0aa6961..ab12d4e 100644 --- a/ProxyDecoder/VLESS.py +++ b/ProxyDecoder/VLESS.py @@ -127,6 +127,6 @@ def decode(url: str) -> dict: if url.split('://')[0] != 'vless': raise Exception('Unexpected scheme') return { - **{'type': 'vless'}, - **__vlessDecode(url) + 'type': 'vless', + 'info': __vlessDecode(url), } diff --git a/ProxyDecoder/VMess.py b/ProxyDecoder/VMess.py index fea58c8..c87ff70 100644 --- a/ProxyDecoder/VMess.py +++ b/ProxyDecoder/VMess.py @@ -222,6 +222,6 @@ def decode(url: str) -> dict: except: raise Exception('Url could not be parsed') return { - **{'type': 'vmess'}, - **vmessInfo + 'type': 'vmess', + 'info': vmessInfo, } diff --git a/ProxyDecoder/__init__.py b/ProxyDecoder/__init__.py index a291772..a774a33 100644 --- a/ProxyDecoder/__init__.py +++ b/ProxyDecoder/__init__.py @@ -1,6 +1,8 @@ #!/usr/bin/python # -*- coding:utf-8 -*- +# TODO: this module will refactor in the future + from ProxyDecoder.decoder import * __all__ = ['decode'] diff --git a/ProxyDecoder/decoder.py b/ProxyDecoder/decoder.py index ca6e0fe..aaca9ef 100644 --- a/ProxyDecoder/decoder.py +++ b/ProxyDecoder/decoder.py @@ -20,7 +20,7 @@ def decode(url: str) -> dict or None: 链接有效: return { 'type': ..., - ... + 'info': {...}, } """ try: