131 lines
5.2 KiB
YAML
131 lines
5.2 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 (tv_config.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 逻辑:计算MD5、注入 sites 并生成最终的 moyu.json
|
|
shell: python
|
|
run: |
|
|
import json
|
|
import os
|
|
import hashlib
|
|
|
|
INPUT_JSON = "tv_config.json"
|
|
OUTPUT_JSON = "moyu.json"
|
|
LOCAL_JAR = "moyu.jar"
|
|
|
|
GITHUB_USER = "woshishiq1"
|
|
GITHUB_REPO = "jiemi"
|
|
|
|
BASE_JAR_URL = f"https://down.nigx.cn/raw.githubusercontent.com/{GITHUB_USER}/{GITHUB_REPO}/main/moyu.jar"
|
|
|
|
# 1. 校验源 JSON 是否存在
|
|
if not os.path.exists(INPUT_JSON):
|
|
print(f"[-] 未找到源文件 {INPUT_JSON}")
|
|
exit(1)
|
|
|
|
# 2. 计算本地下载好的 moyu.jar 的 MD5
|
|
jar_md5 = ""
|
|
if os.path.exists(LOCAL_JAR):
|
|
md5_hash = hashlib.md5()
|
|
with open(LOCAL_JAR, "rb") as f:
|
|
for chunk in iter(lambda: f.read(8192), b""):
|
|
md5_hash.update(chunk)
|
|
jar_md5 = md5_hash.hexdigest()
|
|
print(f"[+] 计算出本地 moyu.jar 的 MD5: {jar_md5}")
|
|
else:
|
|
print("[!] 未找到本地 moyu.jar,将降级使用无 MD5 模式")
|
|
|
|
# 3. 拼接带有 MD5 的完整 JAR URL
|
|
FINAL_JAR_URL = f"{BASE_JAR_URL};md5;{jar_md5}" if jar_md5 else BASE_JAR_URL
|
|
print(f"[+] 最终注入的 JAR 链接: {FINAL_JAR_URL}")
|
|
|
|
# 4. 解析 JSON 并注入
|
|
with open(INPUT_JSON, "r", encoding="utf-8") as f:
|
|
config_data = json.load(f)
|
|
|
|
# A. 更新顶层的 spider 链接为带有 MD5 的地址
|
|
config_data["spider"] = FINAL_JAR_URL
|
|
print("[+] 已更新顶级 spider 链接")
|
|
|
|
# B. 遍历 sites 列表进行注入
|
|
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 或为空 → 注入带 MD5 的链接
|
|
site["jar"] = FINAL_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. 提交最新原版 tv_config.json、修改版 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]"
|
|
|
|
# 强行添加全部 3 个关键文件,保证原版配置与修改版同时同步
|
|
if [ -f "tv_config.json" ]; then git add -f tv_config.json; fi
|
|
if [ -f "moyu.json" ]; then git add -f moyu.json; fi
|
|
if [ -f "moyu.jar" ]; then git add -f moyu.jar; fi
|
|
|
|
# 只要有任何更新就提交
|
|
if ! git diff --cached --quiet; then
|
|
git commit -m "自动同步最新原版配置与moyu文件: $(date +'%Y-%m-%d %H:%M:%S')"
|
|
git push origin HEAD
|
|
echo "【成功】tv_config.json、moyu.json 和 moyu.jar 已同步推送到远程仓库!"
|
|
else
|
|
echo "【提示】内容与上一版本完全一致,无需重复提交。"
|
|
fi
|