feat: 处理脚本独立作者信息

This commit is contained in:
起个名字好难
2025-07-05 00:52:46 +08:00
parent ac72daa9e3
commit 0fc0901766
3 changed files with 104 additions and 124 deletions

37
build/author_config.json Normal file
View File

@@ -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"
}
}

View File

@@ -2,62 +2,36 @@ import os
import sys import sys
import json 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: if len(sys.argv) < 2:
print("请提供要处理的目录路径,例如:") print("用法python js_authors.py <JSON目录路径>")
print(" python authors.py D:\GitHub\bettergi-scripts-list\repo\pathing")
sys.exit(1) sys.exit(1)
folder_path = sys.argv[1] folder_path = sys.argv[1]
if not os.path.exists(folder_path): 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) 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_total = 0
count_modified = 0 count_modified = 0
@@ -66,29 +40,28 @@ for root, dirs, files in os.walk(folder_path):
if filename.endswith("manifest.json"): if filename.endswith("manifest.json"):
count_total += 1 count_total += 1
file_path = os.path.join(root, filename) file_path = os.path.join(root, filename)
print(f"\n🔍 正在处理:{file_path}") print(f"\n🔍 处理文件{file_path}")
try: try:
with open(file_path, "r", encoding="utf-8") as f: with open(file_path, "r", encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
except Exception as e: except Exception as e:
print(f" JSON 解析失败:{e}") print(f"❌ 解析失败:{e}")
continue continue
# info = data.get("info") # info = data.get("info")
# if not isinstance(info, dict): # if not isinstance(info, dict):
# print("⚠️ 缺少 info 字段或格式错误") # print("⚠️ 缺少 info 字段")
# continue # continue
author_field = data.get("authors") author_field = data.get("authors")
if author_field is None: if author_field is None:
print("⚠️ 缺少 author 字段") print("⚠️ 缺少 authors 字段")
continue continue
modified = False modified = False
# 字符串情况(含单人或 & 多人) # 字符串格式处理
# 情况 1字符串类型
if isinstance(author_field, str): if isinstance(author_field, str):
names = [name.strip() for name in author_field.split("&")] names = [name.strip() for name in author_field.split("&")]
new_authors = [] new_authors = []
@@ -102,33 +75,27 @@ for root, dirs, files in os.walk(folder_path):
modified = True modified = True
print("✅ 替换为结构化 author") print("✅ 替换为结构化 author")
# 情况 2列表类型检查每个作者对象 # 列表格式处理
elif isinstance(author_field, list): elif isinstance(author_field, list):
for author_obj in author_field: for author_obj in author_field:
if not isinstance(author_obj, dict): if not isinstance(author_obj, dict):
continue continue
name = author_obj.get("name") name = author_obj.get("name")
if not name: if not name:
continue continue
# 名字替换
new_name = author_rename.get(name, name) new_name = author_rename.get(name, name)
if name != new_name: if name != new_name:
author_obj["name"] = new_name author_obj["name"] = new_name
modified = True modified = True
print(f"📝 重命名:{name}{new_name}") 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") 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 new_name in author_links:
if author_obj.get("links") != author_links[new_name]: if author_obj.get("links") != author_links[new_name]:
author_obj["links"] = author_links[new_name] author_obj["links"] = author_links[new_name]
modified = True modified = True
print(f"🔧 更新链接:{new_name}{author_links[new_name]}") print(f"🔧 更新链接:{new_name}{author_links[new_name]}")
# 否则使用已有字段(如果没有 links
elif "links" not in author_obj and existing_link: elif "links" not in author_obj and existing_link:
author_obj["links"] = existing_link author_obj["links"] = existing_link
modified = True 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: with open(file_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2) json.dump(data, f, ensure_ascii=False, indent=2)
count_modified += 1 count_modified += 1
print("文件已保存") print("写入完成")
else: else:
print("⏭️ 无需修改") print("⏭️ 无需修改")
print(f"\n🎉 全部完成:共检查 {count_total} 个文件,修改了 {count_modified}文件") print(f"\n🎉 处理完成:共 {count_total} JSON 文件,修改了 {count_modified}")

View File

@@ -2,62 +2,36 @@ import os
import sys import sys
import json 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: if len(sys.argv) < 2:
print("请提供要处理的目录路径,例如:") print("用法python pathing_authors.py <JSON目录路径>")
print(" python authors.py D:\GitHub\bettergi-scripts-list\repo\pathing")
sys.exit(1) sys.exit(1)
folder_path = sys.argv[1] folder_path = sys.argv[1]
if not os.path.exists(folder_path): 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) 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_total = 0
count_modified = 0 count_modified = 0
@@ -66,18 +40,18 @@ for root, dirs, files in os.walk(folder_path):
if filename.endswith(".json"): if filename.endswith(".json"):
count_total += 1 count_total += 1
file_path = os.path.join(root, filename) file_path = os.path.join(root, filename)
print(f"\n🔍 正在处理:{file_path}") print(f"\n🔍 处理文件{file_path}")
try: try:
with open(file_path, "r", encoding="utf-8") as f: with open(file_path, "r", encoding="utf-8") as f:
data = json.load(f) data = json.load(f)
except Exception as e: except Exception as e:
print(f" JSON 解析失败:{e}") print(f"❌ 解析失败:{e}")
continue continue
info = data.get("info") info = data.get("info")
if not isinstance(info, dict): if not isinstance(info, dict):
print("⚠️ 缺少 info 字段或格式错误") print("⚠️ 缺少 info 字段")
continue continue
author_field = info.get("author") author_field = info.get("author")
@@ -87,12 +61,11 @@ for root, dirs, files in os.walk(folder_path):
modified = False modified = False
# 字符串情况(含单人或 & 多人) # 字符串格式处理
if isinstance(author_field, str): if isinstance(author_field, str):
names = [name.strip() for name in author_field.split("&")] names = [name.strip() for name in author_field.split("&")]
new_authors = [] new_authors = []
for name in names: for name in names:
# 重命名处理
new_name = author_rename.get(name, name) new_name = author_rename.get(name, name)
author_obj = {"name": new_name} author_obj = {"name": new_name}
if new_name in author_links: if new_name in author_links:
@@ -100,9 +73,9 @@ for root, dirs, files in os.walk(folder_path):
new_authors.append(author_obj) new_authors.append(author_obj)
data["info"]["authors"] = new_authors data["info"]["authors"] = new_authors
modified = True modified = True
print("✅ 替换字符串为结构化 authors") print("✅ 替换为结构化 author")
# 已是结构化数组 # 列表格式处理
elif isinstance(author_field, list): elif isinstance(author_field, list):
for author_obj in author_field: for author_obj in author_field:
if not isinstance(author_obj, dict): if not isinstance(author_obj, dict):
@@ -110,27 +83,30 @@ for root, dirs, files in os.walk(folder_path):
name = author_obj.get("name") name = author_obj.get("name")
if not name: if not name:
continue continue
# 重命名处理
new_name = author_rename.get(name, name) new_name = author_rename.get(name, name)
if name != new_name: if name != new_name:
author_obj["name"] = new_name author_obj["name"] = new_name
modified = True 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: if new_name in author_links:
new_link = author_links[new_name] if author_obj.get("links") != author_links[new_name]:
if author_obj.get("links") != new_link: author_obj["links"] = author_links[new_name]
author_obj["links"] = new_link
modified = True 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: if modified:
with open(file_path, "w", encoding="utf-8") as f: with open(file_path, "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=2) json.dump(data, f, ensure_ascii=False, indent=2)
count_modified += 1 count_modified += 1
print("文件已保存") print("写入完成")
else: else:
print("⏭️ 无需修改") print("⏭️ 无需修改")
print(f"\n🎉 全部完成:共检查 {count_total} 个文件,修改了 {count_modified}文件") print(f"\n🎉 处理完成:共 {count_total} JSON 文件,修改了 {count_modified}")