From 0fc090176692632e841a4c08dd1c78a020394581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B7=E4=B8=AA=E5=90=8D=E5=AD=97=E5=A5=BD=E9=9A=BE?= <25520958+MisakaAldrich@users.noreply.github.com> Date: Sat, 5 Jul 2025 00:52:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A4=84=E7=90=86=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E7=8B=AC=E7=AB=8B=E4=BD=9C=E8=80=85=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/author_config.json | 37 +++++++++++++++ build/js_authors.py | 91 ++++++++++++----------------------- build/pathing_authors.py | 100 +++++++++++++++------------------------ 3 files changed, 104 insertions(+), 124 deletions(-) create mode 100644 build/author_config.json diff --git a/build/author_config.json b/build/author_config.json new file mode 100644 index 00000000..3e89f40d --- /dev/null +++ b/build/author_config.json @@ -0,0 +1,37 @@ +{ + "rename": { + "起个名字好难": "起个名字好难的喵" + }, + "links": { + "秋云": "https://github.com/physligl", + "起个名字好难的喵": "https://github.com/MisakaAldrich", + "火山": "https://github.com/RRRR623", + "mno": "https://github.com/Bedrockx", + "汐": "https://github.com/jiegedabaobei", + "Tool_tingsu": "https://github.com/Tooltingsu", + "吉吉喵": "https://github.com/JJMdzh", + "曦": "https://github.com/cx05121", + "ddaodan": "https://github.com/ddaodan", + "LCB-茶包": "https://github.com/kaedelcb", + "蜜柑魚": "https://github.com/this-Fish", + "彩虹QQ人": "https://github.com/KRdingsan", + "mfkvfhpdx": "https://github.com/mfkvfhpdx", + "提瓦特钓鱼玳师": "https://github.com/Hijiwos", + "柒叶子": "https://github.com/5117600049", + "不瘦五十斤不改名": "https://github.com/PanZic", + "½": "https://github.com/Traveler07", + "Patrick-Ze (AyakaMain)": "https://github.com/Patrick-Ze", + "风埠": "https://github.com/jhkif", + "jbcaaa": "https://github.com/jbcaaa", + "johsang": "https://github.com/johsang", + "寒烟": "https://github.com/214-hanyan", + "灰林鸮": "https://github.com/Strix-nivicolum", + "Tim": "https://github.com/Limint", + "花见木易": "https://github.com/Flower-MUYi", + "无限不循环": "https://github.com/non-repeating001", + "wjdsg": "https://gitee.com/wangjian0327/auto-bgi", + "HZYgrandma": "https://github.com/HZYgrandma", + "huiyadanli": "https://github.com/huiyadanli", + "呱呱z": "https://github.com/jidingcai" + } +} \ No newline at end of file diff --git a/build/js_authors.py b/build/js_authors.py index 29b7c8f1..e0be04ec 100644 --- a/build/js_authors.py +++ b/build/js_authors.py @@ -2,62 +2,36 @@ import os import sys import json -# 指定要处理的文件夹路径 -# folder_path = r"C:\Users\ThinkPadE16\Documents\GitHub\bettergi-scripts-list\repo\pathing" # 修改为你的路径,如 r"C:\Users\..." 或 "./jsons" +# 获取配置文件路径(和脚本在同一目录) +script_dir = os.path.dirname(os.path.abspath(__file__)) +config_path = os.path.join(script_dir, "author_config.json") -# 作者重命名映射:旧名 -> 新名 -author_rename = { - "起个名字好难": "起个名字好难的喵", -} - -# 作者映射表:用于自动填入 links -author_links = { - "秋云": "https://github.com/physligl", - "起个名字好难的喵": "https://github.com/MisakaAldrich", - "火山": "https://github.com/RRRR623", - "mno": "https://github.com/Bedrockx", - "汐": "https://github.com/jiegedabaobei", - "Tool_tingsu": "https://github.com/Tooltingsu", - "吉吉喵": "https://github.com/JJMdzh", - "曦": "https://github.com/cx05121", - "ddaodan": "https://github.com/ddaodan", - "LCB-茶包": "https://github.com/kaedelcb", - "蜜柑魚": "https://github.com/this-Fish", - "彩虹QQ人":"https://github.com/KRdingsan", - "mfkvfhpdx": "https://github.com/mfkvfhpdx", - "提瓦特钓鱼玳师": "https://github.com/Hijiwos", - "柒叶子": "https://github.com/5117600049", - "不瘦五十斤不改名": "https://github.com/PanZic", - "½": "https://github.com/Traveler07", - "Patrick-Ze (AyakaMain)": "https://github.com/Patrick-Ze", - "风埠": "https://github.com/jhkif", - "jbcaaa":"https://github.com/jbcaaa", - "johsang":"https://github.com/johsang", - "寒烟": "https://github.com/214-hanyan", - "灰林鸮": "https://github.com/Strix-nivicolum", - "Tim": "https://github.com/Limint", - "花见木易": "https://github.com/Flower-MUYi", - "无限不循环": "https://github.com/non-repeating001", - "wjdsg": "https://gitee.com/wangjian0327/auto-bgi", - "HZYgrandma": "https://github.com/HZYgrandma", - "huiyadanli": "https://github.com/huiyadanli", - "呱呱z": "https://github.com/jidingcai" -} - -# 获取命令行参数 +# 获取要处理的文件夹路径 if len(sys.argv) < 2: - print("❌ 请提供要处理的目录路径,例如:") - print(" python authors.py D:\GitHub\bettergi-scripts-list\repo\pathing") + print("❌ 用法:python js_authors.py ") sys.exit(1) folder_path = sys.argv[1] if not os.path.exists(folder_path): - print(f"❌ 路径不存在:{folder_path}") + print(f"❌ JSON目录不存在:{folder_path}") + sys.exit(1) +if not os.path.exists(config_path): + print(f"❌ 配置文件不存在:{config_path}") sys.exit(1) -print(f"🚀 启动,递归处理文件夹:{folder_path}") +# 加载配置 +try: + with open(config_path, "r", encoding="utf-8") as f: + config = json.load(f) +except Exception as e: + print(f"❌ 配置文件加载失败:{e}") + sys.exit(1) +author_rename = config.get("rename", {}) +author_links = config.get("links", {}) + +print(f"🚀 启动,处理目录:{folder_path}") count_total = 0 count_modified = 0 @@ -66,29 +40,28 @@ for root, dirs, files in os.walk(folder_path): if filename.endswith("manifest.json"): count_total += 1 file_path = os.path.join(root, filename) - print(f"\n🔍 正在处理:{file_path}") + print(f"\n🔍 处理文件:{file_path}") try: with open(file_path, "r", encoding="utf-8") as f: data = json.load(f) except Exception as e: - print(f"❌ JSON 解析失败:{e}") + print(f"❌ 解析失败:{e}") continue # info = data.get("info") # if not isinstance(info, dict): - # print("⚠️ 缺少 info 字段或格式错误") + # print("⚠️ 缺少 info 字段") # continue author_field = data.get("authors") if author_field is None: - print("⚠️ 缺少 author 字段") + print("⚠️ 缺少 authors 字段") continue modified = False - # 字符串情况(含单人或 & 多人) - # 情况 1:字符串类型 + # 字符串格式处理 if isinstance(author_field, str): names = [name.strip() for name in author_field.split("&")] new_authors = [] @@ -102,33 +75,27 @@ for root, dirs, files in os.walk(folder_path): modified = True print("✅ 替换为结构化 author") - # 情况 2:列表类型,检查每个作者对象 + # 列表格式处理 elif isinstance(author_field, list): for author_obj in author_field: if not isinstance(author_obj, dict): continue - name = author_obj.get("name") if not name: continue - - # 名字替换 new_name = author_rename.get(name, name) if name != new_name: author_obj["name"] = new_name modified = True print(f"📝 重命名:{name} → {new_name}") - # 找所有可能字段(link, url, links) + # 统一链接字段名 existing_link = author_obj.pop("link", None) or author_obj.pop("url", None) or author_obj.get("links") - - # 如果映射表有 → 使用 if new_name in author_links: if author_obj.get("links") != author_links[new_name]: author_obj["links"] = author_links[new_name] modified = True print(f"🔧 更新链接:{new_name} → {author_links[new_name]}") - # 否则使用已有字段(如果没有 links) elif "links" not in author_obj and existing_link: author_obj["links"] = existing_link modified = True @@ -138,8 +105,8 @@ for root, dirs, files in os.walk(folder_path): with open(file_path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=2) count_modified += 1 - print("✅ 文件已保存") + print("✅ 写入完成") else: print("⏭️ 无需修改") -print(f"\n🎉 全部完成:共检查 {count_total} 个文件,修改了 {count_modified} 个文件") \ No newline at end of file +print(f"\n🎉 处理完成:共 {count_total} 个 JSON 文件,修改了 {count_modified} 个") diff --git a/build/pathing_authors.py b/build/pathing_authors.py index abaa0985..2d730b85 100644 --- a/build/pathing_authors.py +++ b/build/pathing_authors.py @@ -2,62 +2,36 @@ import os import sys import json -# 指定要处理的文件夹路径 -# folder_path = r"C:\Users\ThinkPadE16\Documents\GitHub\bettergi-scripts-list\repo\pathing" # 修改为你的路径,如 r"C:\Users\..." 或 "./jsons" +# 获取配置文件路径(和脚本在同一目录) +script_dir = os.path.dirname(os.path.abspath(__file__)) +config_path = os.path.join(script_dir, "author_config.json") -# 作者重命名映射:旧名 -> 新名 -author_rename = { - "起个名字好难": "起个名字好难的喵", -} - -# 作者映射表:用于自动填入 links -author_links = { - "秋云": "https://github.com/physligl", - "起个名字好难的喵": "https://github.com/MisakaAldrich", - "火山": "https://github.com/RRRR623", - "mno": "https://github.com/Bedrockx", - "汐": "https://github.com/jiegedabaobei", - "Tool_tingsu": "https://github.com/Tooltingsu", - "吉吉喵": "https://github.com/JJMdzh", - "曦": "https://github.com/cx05121", - "ddaodan": "https://github.com/ddaodan", - "LCB-茶包": "https://github.com/kaedelcb", - "蜜柑魚": "https://github.com/this-Fish", - "彩虹QQ人":"https://github.com/KRdingsan", - "mfkvfhpdx": "https://github.com/mfkvfhpdx", - "提瓦特钓鱼玳师": "https://github.com/Hijiwos", - "柒叶子": "https://github.com/5117600049", - "不瘦五十斤不改名": "https://github.com/PanZic", - "½": "https://github.com/Traveler07", - "Patrick-Ze (AyakaMain)": "https://github.com/Patrick-Ze", - "风埠": "https://github.com/jhkif", - "jbcaaa":"https://github.com/jbcaaa", - "johsang":"https://github.com/johsang", - "寒烟": "https://github.com/214-hanyan", - "灰林鸮": "https://github.com/Strix-nivicolum", - "Tim": "https://github.com/Limint", - "花见木易": "https://github.com/Flower-MUYi", - "无限不循环": "https://github.com/non-repeating001", - "wjdsg": "https://gitee.com/wangjian0327/auto-bgi", - "HZYgrandma": "https://github.com/HZYgrandma", - "huiyadanli": "https://github.com/huiyadanli", - "呱呱z": "https://github.com/jidingcai" -} - -# 获取命令行参数 +# 获取要处理的文件夹路径 if len(sys.argv) < 2: - print("❌ 请提供要处理的目录路径,例如:") - print(" python authors.py D:\GitHub\bettergi-scripts-list\repo\pathing") + print("❌ 用法:python pathing_authors.py ") sys.exit(1) folder_path = sys.argv[1] if not os.path.exists(folder_path): - print(f"❌ 路径不存在:{folder_path}") + print(f"❌ JSON目录不存在:{folder_path}") + sys.exit(1) +if not os.path.exists(config_path): + print(f"❌ 配置文件不存在:{config_path}") sys.exit(1) -print(f"🚀 启动,递归处理文件夹:{folder_path}") +# 加载配置 +try: + with open(config_path, "r", encoding="utf-8") as f: + config = json.load(f) +except Exception as e: + print(f"❌ 配置文件加载失败:{e}") + sys.exit(1) +author_rename = config.get("rename", {}) +author_links = config.get("links", {}) + +print(f"🚀 启动,处理目录:{folder_path}") count_total = 0 count_modified = 0 @@ -66,18 +40,18 @@ for root, dirs, files in os.walk(folder_path): if filename.endswith(".json"): count_total += 1 file_path = os.path.join(root, filename) - print(f"\n🔍 正在处理:{file_path}") + print(f"\n🔍 处理文件:{file_path}") try: with open(file_path, "r", encoding="utf-8") as f: data = json.load(f) except Exception as e: - print(f"❌ JSON 解析失败:{e}") + print(f"❌ 解析失败:{e}") continue info = data.get("info") if not isinstance(info, dict): - print("⚠️ 缺少 info 字段或格式错误") + print("⚠️ 缺少 info 字段") continue author_field = info.get("author") @@ -87,12 +61,11 @@ for root, dirs, files in os.walk(folder_path): modified = False - # 字符串情况(含单人或 & 多人) + # 字符串格式处理 if isinstance(author_field, str): names = [name.strip() for name in author_field.split("&")] new_authors = [] for name in names: - # 重命名处理 new_name = author_rename.get(name, name) author_obj = {"name": new_name} if new_name in author_links: @@ -100,9 +73,9 @@ for root, dirs, files in os.walk(folder_path): new_authors.append(author_obj) data["info"]["authors"] = new_authors modified = True - print("✅ 替换字符串为结构化 authors") + print("✅ 替换为结构化 author") - # 已是结构化数组 + # 列表格式处理 elif isinstance(author_field, list): for author_obj in author_field: if not isinstance(author_obj, dict): @@ -110,27 +83,30 @@ for root, dirs, files in os.walk(folder_path): name = author_obj.get("name") if not name: continue - # 重命名处理 new_name = author_rename.get(name, name) if name != new_name: author_obj["name"] = new_name modified = True - print(f"📝 重命名作者:{name} → {new_name}") + print(f"📝 重命名:{name} → {new_name}") - # 更新链接 + # 统一链接字段名 + existing_link = author_obj.pop("link", None) or author_obj.pop("url", None) or author_obj.get("links") if new_name in author_links: - new_link = author_links[new_name] - if author_obj.get("links") != new_link: - author_obj["links"] = new_link + if author_obj.get("links") != author_links[new_name]: + author_obj["links"] = author_links[new_name] modified = True - print(f"🔧 更新链接:{new_name} → {new_link}") + print(f"🔧 更新链接:{new_name} → {author_links[new_name]}") + elif "links" not in author_obj and existing_link: + author_obj["links"] = existing_link + modified = True + print(f"🔄 标准化已有链接字段为 links → {existing_link}") if modified: with open(file_path, "w", encoding="utf-8") as f: json.dump(data, f, ensure_ascii=False, indent=2) count_modified += 1 - print("✅ 文件已保存") + print("✅ 写入完成") else: print("⏭️ 无需修改") -print(f"\n🎉 全部完成:共检查 {count_total} 个文件,修改了 {count_modified} 个文件") \ No newline at end of file +print(f"\n🎉 处理完成:共 {count_total} 个 JSON 文件,修改了 {count_modified} 个")