112 lines
4.6 KiB
YAML
112 lines
4.6 KiB
YAML
name: 自动调用API解密并注入Sites生成moyu.json
|
||
|
||
on:
|
||
schedule:
|
||
- cron: '0 */3 * * *' # 每3小时 自动运行
|
||
workflow_dispatch: # 支持手动点击按钮运行
|
||
|
||
jobs:
|
||
decrypt_and_process:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: 检出仓库代码
|
||
uses: actions/checkout@v4
|
||
|
||
- name: 1. 请求解密接口并保存基础 JSON
|
||
run: |
|
||
curl -X POST "http://2015888.xyz/jiemi/get_jiemi.php" \
|
||
-H "Content-Type: application/x-www-form-urlencoded" \
|
||
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \
|
||
-d "url=http://摸鱼儿.cc" \
|
||
-o tv_config.json
|
||
|
||
- name: 2. 自动下载最新的真实 jar 并重命名为 moyu.jar
|
||
run: |
|
||
if [ -f "tv_config.json" ] && grep -q -E "spider|sites" tv_config.json; then
|
||
# 动态提取原作者最新的 jar 链接
|
||
JAR_URL=$(grep -oP '"spider"\s*:\s*"\K[^"]+' tv_config.json | cut -d';' -f1)
|
||
if [ -n "$JAR_URL" ] && [[ "$JAR_URL" == http* ]]; then
|
||
echo "成功抓取到远程 JAR 地址: $JAR_URL"
|
||
curl -L "$JAR_URL" -o moyu.jar
|
||
echo "已成功将最新的 jar 下载并重命名为 moyu.jar"
|
||
else
|
||
echo "提示:未在配置中找到远程 JAR 链接。"
|
||
fi
|
||
else
|
||
echo "【错误】解密出来的基础 JSON 结构不合法!"
|
||
exit 1
|
||
fi
|
||
|
||
- name: 3. 运行内置 Python 逻辑:注入 sites 并生成最终的 moyu.json
|
||
shell: python
|
||
run: |
|
||
import json
|
||
import os
|
||
|
||
INPUT_JSON = "tv_config.json"
|
||
OUTPUT_JSON = "moyu.json"
|
||
|
||
# 你的 GitHub 仓库对应的 moyu.jar 纯净链接(不带 MD5)
|
||
# 【请注意】:请把下面两行的“你的GitHub用户名”和“你的仓库名”修改为你实际的名称
|
||
GITHUB_USER = "woshishiq1"
|
||
GITHUB_REPO = "jiemi"
|
||
|
||
BASE_JAR_URL = f"https://down.nigx.cn/raw.githubusercontent.com/{GITHUB_USER}/{GITHUB_REPO}/main/moyu.jar"
|
||
|
||
if not os.path.exists(INPUT_JSON):
|
||
print(f"[-] 未找到源文件 {INPUT_JSON}")
|
||
exit(1)
|
||
|
||
with open(INPUT_JSON, "r", encoding="utf-8") as f:
|
||
config_data = json.load(f)
|
||
|
||
# A. 顺便把最顶层的顶级 spider 链接也改成你自己的 moyu.jar
|
||
config_data["spider"] = BASE_JAR_URL
|
||
print("[+] 已更新顶级 spider 链接")
|
||
|
||
# B. 遍历 sites 列表,无 jar 或 jar 为空的站点自动注入
|
||
sites_list = config_data.get("sites", [])
|
||
if isinstance(sites_list, list):
|
||
updated_count = 0
|
||
skipped_count = 0
|
||
|
||
for site in sites_list:
|
||
if isinstance(site, dict):
|
||
site_name = site.get("name", "未知站点")
|
||
current_jar = site.get("jar")
|
||
|
||
# 如果已有有效的 jar 地址则跳过
|
||
if current_jar and isinstance(current_jar, str) and current_jar.strip():
|
||
skipped_count += 1
|
||
continue
|
||
|
||
# 没有 jar 或为空 → 注入你自己的纯净链接
|
||
site["jar"] = BASE_JAR_URL
|
||
updated_count += 1
|
||
|
||
print(f"[+] Sites 注入完成:更新了 {updated_count} 个站点,跳过了 {skipped_count} 个已有 jar 的站点")
|
||
|
||
# C. 统一写出为最终文件名 moyu.json
|
||
with open(OUTPUT_JSON, "w", encoding="utf-8") as f:
|
||
json.dump(config_data, f, indent=2, ensure_ascii=False)
|
||
print(f"[+] 最终配置文件已成功生成: {OUTPUT_JSON}")
|
||
|
||
- name: 4. 强行提交最新的 moyu.json 和 moyu.jar 到仓库
|
||
run: |
|
||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||
git config --local user.name "github-actions[bot]"
|
||
|
||
# 强行添加,确保绕过任何 .gitignore 规则
|
||
if [ -f "moyu.json" ]; then git add -f moyu.json; fi
|
||
if [ -f "moyu.jar" ]; then git add -f moyu.jar; fi
|
||
|
||
# 只要代码、配置或 jar 包有任何风吹草动,Git 都会自动捕捉并更新
|
||
if ! git diff --cached --quiet; then
|
||
git commit -m "自动同步最新moyu.json与moyu.jar: $(date +'%Y-%m-%d %H:%M:%S')"
|
||
git push origin HEAD
|
||
echo "【成功】moyu.json 和 moyu.jar 已成功推送到你的远程仓库!"
|
||
else
|
||
echo "【提示】内容与上一版本完全一致,无需重复提交。"
|
||
fi
|