Sync and Compile Emby Rules #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync and Compile Emby Rules | |
on: | |
schedule: | |
- cron: '0 18 * * *' # 每天北京时间02:00执行 | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
emby_rules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Git user | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
- name: Install mihomo | |
run: | | |
version=$(curl -sL https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/version.txt) | |
curl -sL "https://github.com/MetaCubeX/mihomo/releases/download/Prerelease-Alpha/mihomo-linux-amd64-${version}.gz" | \ | |
gunzip -c > /usr/local/bin/mihomo && chmod +x /usr/local/bin/mihomo | |
- name: Fetch and Merge Emby Rules | |
run: | | |
mkdir -p rules/Domain # 确保目录存在 | |
# 下载 Emby 规则文件 | |
curl -sL "https://raw.githubusercontent.com/Lanlan13-14/Rules/refs/heads/main/rules/Domain/emby.list" -o rules/Domain/emby1.list | |
curl -sL "https://raw.githubusercontent.com/666OS/YYDS/main/mihomo/rules/emby.list" -o rules/Domain/emby2.list | |
# 合并去重并排除包含 IC DR 的规则 | |
cat rules/Domain/emby1.list rules/Domain/emby2.list | grep -v '^#' | grep -v 'IC DR' | sort -u > rules/Domain/merged_emby.list | |
- name: Convert Emby Rules to YAML | |
run: | | |
echo "payload:" > rules/Domain/emby.yaml | |
while IFS=, read -r type value; do | |
if [[ -n "$type" && -n "$value" ]]; then | |
# 处理 DOMAIN 规则,直接加入 | |
if [[ "$type" == "DOMAIN" ]]; then | |
echo " - $value" >> rules/Domain/emby.yaml | |
# 处理 DOMAIN-SUFFIX 规则,加上 *. | |
elif [[ "$type" == "DOMAIN-SUFFIX" ]]; then | |
echo " - '*.$value'" >> rules/Domain/emby.yaml | |
fi | |
fi | |
done < rules/Domain/merged_emby.list | |
- name: Convert Emby Rules to MRS | |
run: | | |
# 使用 mihomo 转换为 MRS 格式 | |
mihomo convert-ruleset domain yaml rules/Domain/emby.yaml rules/Domain/emby.mrs | |
- name: Clean up the source files | |
run: | | |
# 删除源文件 | |
rm -f rules/Domain/emby1.list rules/Domain/emby2.list rules/Domain/merged_emby.list | |
- name: Commit and Push Changes | |
run: | | |
git add . | |
git diff-index --quiet HEAD -- || (git commit -m "Updated Emby rules (merged emby.list -> emby.mrs)" && git push) |