Skip to content

Commit

Permalink
Special handling for Surge.
Browse files Browse the repository at this point in the history
  • Loading branch information
xkww3n committed Nov 4, 2023
1 parent ed25fbb commit 7c2ea70
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,24 @@
ruleset_domestic = geosite.parse(src_domestic, None, ["!cn"])
logger.info(f"Imported {len(ruleset_domestic)} domestic rules from v2fly geolocation-cn list.")

for item in ruleset_domestic.copy():
tld_overseas = (".hk", ".kr", ".my", ".sg", ".au", ".tw", ".in", ".ru", ".us", ".fr", ".th", ".id", ".jp")
if any([item.Payload.endswith(os_tld) for os_tld in tld_overseas]):
ruleset_domestic.remove(item)
logger.debug(f"{item} removed for having a overseas TLD.")
ruleset_domestic = rule.apply_patch(ruleset_domestic, "domestic")
ruleset_domestic = rule.dedup(ruleset_domestic)
ruleset_domestic.sort()
# Surge ignores eTLDs in the domain set. So it needs a not-optimised version.
rule.batch_dump(ruleset_domestic, ["text"], const.PATH_DIST, "domestic_withcntld")

# Add all domestic TLDs to domestic rules, then perform deduplication.
src_domestic_tlds = set(open(const.PATH_SOURCE_V2FLY/"tld-cn", mode="r", encoding="utf-8").read().splitlines())
ruleset_domestic_tlds = geosite.parse(src_domestic_tlds)
logger.info(f"Imported {len(ruleset_domestic_tlds)} domestic TLDs.")
ruleset_domestic |= ruleset_domestic_tlds
ruleset_domestic = rule.apply_patch(ruleset_domestic, "domestic")
ruleset_domestic = rule.dedup(ruleset_domestic)
for item in ruleset_domestic.copy():
tld_overseas = (".hk", ".kr", ".my", ".sg", ".au", ".tw", ".in", ".ru", ".us", ".fr", ".th", ".id", ".jp")
if any([item.Payload.endswith(os_tld) for os_tld in tld_overseas]):
ruleset_domestic.remove(item)
logger.debug(f"{item} removed for having a overseas TLD.")
logger.info(f"Generated {len(ruleset_domestic)} domestic rules.")

ruleset_domestic.sort()
rule.batch_dump(ruleset_domestic, const.TARGETS, const.PATH_DIST, "domestic")

END_TIME = time_ns()
Expand Down

0 comments on commit 7c2ea70

Please sign in to comment.