feat: json exports/imports
This commit is contained in:
18 files changed
+778
-42
No files matched your search
@@ -20,6 +20,9 @@ def main() -> None:
|
||||
)
|
||||
ap.add_argument("--backend", choices=["sing-box", "xray", "hybrid"], default="sing-box")
|
||||
ap.add_argument("--routing-mark", type=int, default=None, dest="routing_mark")
|
||||
ap.add_argument(
|
||||
"--links-out", default=None, dest="links_out", help="Also write {tag: original URI} here, for sharing."
|
||||
)
|
||||
args = ap.parse_args()
|
||||
|
||||
url = sys.stdin.read().strip()
|
||||
@@ -34,17 +37,21 @@ def main() -> None:
|
||||
sys.exit(1)
|
||||
|
||||
lines = decode_subscription(raw)
|
||||
links: dict[str, str] = {}
|
||||
if args.backend == "hybrid":
|
||||
outbounds = parse_hybrid_subscription(lines, args.tag_prefix, args.routing_mark)
|
||||
outbounds = parse_hybrid_subscription(lines, args.tag_prefix, args.routing_mark, links)
|
||||
has_outbounds = bool(outbounds["singBox"] or outbounds["xray"])
|
||||
else:
|
||||
outbounds = parse_subscription(lines, args.tag_prefix, args.routing_mark, args.backend)
|
||||
outbounds = parse_subscription(lines, args.tag_prefix, args.routing_mark, args.backend, links)
|
||||
has_outbounds = bool(outbounds)
|
||||
|
||||
if not has_outbounds:
|
||||
print("error: subscription contained no parseable proxy URIs", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if args.links_out:
|
||||
with open(args.links_out, "w", encoding="utf-8") as handle:
|
||||
json.dump(links, handle)
|
||||
print(json.dumps(outbounds))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user