mirror of
https://github.com/KaringX/karing-ruleset.git
synced 2025-06-08 10:04:13 +08:00
cn_adblockfilters.sh
This commit is contained in:
parent
6ef3f9d82c
commit
f0c873c48a
8
.github/workflows/run.yml
vendored
8
.github/workflows/run.yml
vendored
@ -40,7 +40,7 @@ jobs:
|
||||
NO_SKIP: true
|
||||
run: |
|
||||
cd sing-rule || exit 1
|
||||
wget -q https://github.com/SagerNet/sing-box/releases/download/v1.10.0-beta.4/sing-box-1.10.0-beta.4-linux-amd64.tar.gz -O sing-box.tar.gz && tar zxvf sing-box.tar.gz && mv sing-box-1.10.0-beta.4-linux-amd64/sing-box ./
|
||||
wget -q https://github.com/SagerNet/sing-box/releases/download/v1.10.7/sing-box-1.10.7-linux-amd64.tar.gz -O sing-box.tar.gz && tar zxvf sing-box.tar.gz && mv sing-box-1.10.7-linux-amd64/sing-box ./
|
||||
chmod 755 sing-box ACL4SSR/convert_srs.sh && ./ACL4SSR/convert_srs.sh ./sing-box
|
||||
rm -rf LICENSE README.md ACL4SSR/convert_*
|
||||
cp ./ACL4SSR/Ruleset/*.srs ./ACL4SSR
|
||||
@ -67,6 +67,12 @@ jobs:
|
||||
cp -r ../meta-rules-dat/geo ./
|
||||
bash ../workflow/resouces/merge_geo_ir.sh ./geo ../Iran-sing-box-rules/
|
||||
|
||||
- name: CN adblockfilters
|
||||
env:
|
||||
NO_SKIP: true
|
||||
run: |
|
||||
bash ../workflow/resouces/cn_adblockfilters.sh ./sing-rule
|
||||
|
||||
- name: RU antizapret
|
||||
env:
|
||||
NO_SKIP: true
|
||||
|
83
resouces/cn_adblockfilters.sh
Normal file
83
resouces/cn_adblockfilters.sh
Normal file
@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
##adblockfilters
|
||||
# adblockclashlite.list 更新至 ACL:BanAD
|
||||
# https://github.com/217heidai/adblockfilters
|
||||
#
|
||||
|
||||
CURRENT_DIR=$(cd $(dirname $0); pwd)
|
||||
|
||||
target_dir=$1
|
||||
if [ -z "$target_dir" ]; then
|
||||
target_dir=$CURRENT_DIR
|
||||
fi
|
||||
|
||||
if [ ! -d "$target_dir" ]; then
|
||||
echo "${target_dir} unkown directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
work_dir=$(realpath "$target_dir")
|
||||
target_dir="${work_dir}/chinese"
|
||||
sing_exe="${work_dir}/sing-box"
|
||||
|
||||
# ———————————————————————————————————————————————————————————————————————————————————————————————
|
||||
|
||||
function download_adblockfilters() {
|
||||
mkdir -p $target_dir/adblockfilters
|
||||
cd $target_dir/adblockfilters/
|
||||
|
||||
file_array=("AdGuard_Base_filter.txt" "AdGuard_Chinese_filter.txt" "AdGuard_DNS_filter.txt" "AdGuard_Mobile_Ads_filter.txt" "adblockclashlite.list" "adblockclash.list")
|
||||
for file in "${file_array[@]}"; do
|
||||
wget --no-check-certificate -q --show-progress -T10 -t3 -O $file "https://github.com/217heidai/adblockfilters/raw/refs/heads/main/rules/${file}"
|
||||
|
||||
if [[ "$file" == *.list ]]; then
|
||||
|
||||
basename=${file%.list}
|
||||
echo "source << ${basename}"
|
||||
#convert to json
|
||||
python $CURRENT_DIR/convert_json.py --single $target_dir/adblockfilters/$file $basename.json
|
||||
|
||||
#convert to srs
|
||||
srs_file=${basename}.srs
|
||||
$sing_exe rule-set compile $basename.json -o $srs_file
|
||||
echo -e "output >> ${srs_file}\n"
|
||||
fi
|
||||
done
|
||||
|
||||
# BanAD
|
||||
acl_dir=$work_dir/ACL4SSR
|
||||
echo "copy adblockclashlite:BanAD to ${acl_dir}"
|
||||
cp ./adblockclashlite.json $acl_dir/BanAD.json
|
||||
cp ./adblockclashlite.srs $acl_dir/BanAD.srs
|
||||
|
||||
# AdGuard
|
||||
adguard_dir=$work_dir/AdGuard
|
||||
if [ -d "$adguard_dir" ]; then
|
||||
echo "move AdGuard files to ${adguard_dir}"
|
||||
mv ./AdGuard* $adguard_dir/
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
# ———————————————————————————————————————————————————————————————————————————————————————————————
|
||||
chmod +x $sing_exe
|
||||
# rm -rf $target_dir
|
||||
mkdir $target_dir ; cd $target_dir
|
||||
echo "start<= ${target_dir}"
|
||||
|
||||
download_adblockfilters
|
||||
|
||||
echo "end<= ${target_dir}"
|
||||
#END FILE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -3,6 +3,7 @@ import sys
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
from helper.helper import debug_log as deug_log
|
||||
|
||||
MAP_RULES_KEY_DICT = {
|
||||
'IP-CIDR': 'ip_cidr',
|
||||
@ -22,9 +23,9 @@ ADDON_ADBLOCK_DOMAINS = {
|
||||
}
|
||||
|
||||
|
||||
def deug_log(msg: str):
|
||||
print(msg)
|
||||
pass
|
||||
# def deug_log(msg: str):
|
||||
# print(msg)
|
||||
# pass
|
||||
|
||||
|
||||
def main(src_path: str, out_path: str = None):
|
||||
@ -121,7 +122,7 @@ def converto_json(src_file: str, out_path: str):
|
||||
out_file = os.path.join(out_path, os.path.basename(splits[0]) + ".json")
|
||||
content = read_rules_from_file(src_file)
|
||||
if content is None:
|
||||
return
|
||||
return False
|
||||
|
||||
return writeto_rulefile(out_file, content)
|
||||
# END converto_josn
|
||||
@ -132,6 +133,8 @@ def writeto_rulefile(out_file: str, content: dict):
|
||||
with open(out_file, "w") as json_file:
|
||||
json_file.write(json_string)
|
||||
deug_log(f"wirte to {out_file}")
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
## Addon
|
||||
@ -183,6 +186,15 @@ def extract_strings_from_dict(data_dict, my_dict=None):
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3:
|
||||
print("Usage: python script.py <first_parameter> <second_parameter>")
|
||||
|
||||
elif sys.argv[1] == "--single":
|
||||
src_file = sys.argv[2]
|
||||
out_path = os.path.dirname(src_file)
|
||||
content = converto_json(src_file, out_path)
|
||||
if content is False:
|
||||
deug_log(f"src file:{src_file} empty")
|
||||
exit(-1)
|
||||
|
||||
else:
|
||||
src_path = get_out_path(sys.argv[1])
|
||||
out_path = get_out_path(sys.argv[2])
|
||||
|
@ -16,6 +16,9 @@ if [ ! -d "$target_dir" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
work_dir=$(realpath "$target_dir")
|
||||
target_dir="${work_dir}/russia"
|
||||
|
||||
# ———————————————————————————————————————————————————————————————————————————————————————————————
|
||||
|
||||
## runetfreedom/russia-v2ray-rules-dat
|
||||
@ -37,14 +40,12 @@ function download_antizapret(){
|
||||
|
||||
file_array=("antizapret.srs" "antizapret.srs.sha256sum")
|
||||
for file in "${file_array[@]}"; do
|
||||
echo $file
|
||||
wget --no-check-certificate -q --show-progress -T10 -t3 "https://github.com/savely-krasovsky/antizapret-sing-box/releases/latest/download/${file}"
|
||||
echo $file
|
||||
wget --no-check-certificate -q --show-progress -T10 -t3 "https://github.com/savely-krasovsky/antizapret-sing-box/releases/latest/download/${file}"
|
||||
done
|
||||
}
|
||||
|
||||
# ———————————————————————————————————————————————————————————————————————————————————————————————
|
||||
work_dir=$(realpath "$target_dir")
|
||||
target_dir="${work_dir}/russia"
|
||||
|
||||
rm -rf $target_dir ; mkdir $target_dir ; cd $target_dir
|
||||
echo "start<= ${target_dir}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user