USAGE.md
· 817 B · Markdown
Raw
整理好表情包为如下格式:
```markdown
. 📂 owo
└── 📂 bilibili/
│ ├── 📄 bilibili-doge.png
│ ├── 📄 bilibili-大佬.png
│ ├── 📄 …………
└── 📂 blobcat/
│ ├── 📄 blobcat0_0.png
│ ├── 📄 blobcatalt.png
│ ├── 📄 blobcatangry.png
│ ├── 📄 …………
└── 📂 linedog/
│ ├── 📄 linedog-不要.gif
│ ├── 📄 linedog-写不完了.gif
│ ├── 📄 linedog-准备.gif
│ ├── 📄 …………
└── 📂 liushen/
│ ├── 📄 liushen-angry.png
│ ├── 📄 liushen-chowdown.png
│ ├── 📄 liushen-cold.png
│ ├── 📄 …………
├── 📄 main.py
```
执行脚本即可,注意修改脚本中的文件夹列表和映射关系
整理好表情包为如下格式:
. 📂 owo
└── 📂 bilibili/
│ ├── 📄 bilibili-doge.png
│ ├── 📄 bilibili-大佬.png
│ ├── 📄 …………
└── 📂 blobcat/
│ ├── 📄 blobcat0_0.png
│ ├── 📄 blobcatalt.png
│ ├── 📄 blobcatangry.png
│ ├── 📄 …………
└── 📂 linedog/
│ ├── 📄 linedog-不要.gif
│ ├── 📄 linedog-写不完了.gif
│ ├── 📄 linedog-准备.gif
│ ├── 📄 …………
└── 📂 liushen/
│ ├── 📄 liushen-angry.png
│ ├── 📄 liushen-chowdown.png
│ ├── 📄 liushen-cold.png
│ ├── 📄 …………
├── 📄 main.py
执行脚本即可,注意修改脚本中的文件夹列表和映射关系
generate-owo-artalk.py
· 3.0 KiB · Python
Raw
import os
import json
def generate_artalk_emojis(base_url, emoji_folders, output_path='.json/artalk-emoji.json', origin=None):
"""
生成 Artalk 表情包 JSON 文件
参数:
base_url: 基础 BASE URL
emoji_folders: 包含表情包的文件夹列表
output_path: 输出 JSON 文件的路径
origin: 原始表情包数据,包含网址到名称的映射关系
"""
result = []
# 创建网址到名称的映射字典
url_to_key_map = {}
if origin:
for group in origin:
for item in group.get("items", []):
if "val" in item and "key" in item:
# 去除可能存在的反引号
val = item["val"].replace("`", "").strip()
url_to_key_map[val] = item["key"]
for folder in emoji_folders:
if not os.path.isdir(folder):
print(f"警告: {folder} 不是一个文件夹,已跳过")
continue
emoji_group = {
"name": folder,
"type": "image",
"items": []
}
# 获取文件夹中的所有文件
files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]
for file in files:
# 获取文件名(不带扩展名)
filename_without_ext = os.path.splitext(file)[0]
# 构建完整URL
full_url = f"{base_url}/{folder}/{file}"
# 检查是否在原始数据中存在该URL,如果存在则使用原始key
key = url_to_key_map.get(full_url, filename_without_ext)
# 创建表情项
emoji_item = {
"key": key,
"val": full_url
}
emoji_group["items"].append(emoji_item)
if emoji_group["items"]: # 只添加非空的表情组
result.append(emoji_group)
# 确保输出目录存在
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# 写入 JSON 文件
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
print(f"表情包 JSON 文件已生成: {output_path}")
if __name__ == "__main__":
base_url = "https://jsd.example.com/gh/willow-god/owo/"
folders = ["liushen", "blobcat", "linedog", "bilibili"]
origin_json = ".json/artalk-emoji.json"
output = ".json/artalk-emoji.json"
# 加载原始表情包数据(如果存在)
origin_data = None
try:
with open(origin_json, 'r', encoding='utf-8') as f:
origin_data = json.load(f)
print(f"已加载原始表情包数据: {origin_json}")
except FileNotFoundError:
print(f"未找到原始表情包数据文件: {origin_json}")
except json.JSONDecodeError:
print(f"原始表情包数据文件格式错误: {origin_json}")
generate_artalk_emojis(base_url, folders, output, origin_data)
| 1 | import os |
| 2 | import json |
| 3 | |
| 4 | def generate_artalk_emojis(base_url, emoji_folders, output_path='.json/artalk-emoji.json', origin=None): |
| 5 | """ |
| 6 | 生成 Artalk 表情包 JSON 文件 |
| 7 | |
| 8 | 参数: |
| 9 | base_url: 基础 BASE URL |
| 10 | emoji_folders: 包含表情包的文件夹列表 |
| 11 | output_path: 输出 JSON 文件的路径 |
| 12 | origin: 原始表情包数据,包含网址到名称的映射关系 |
| 13 | """ |
| 14 | result = [] |
| 15 | |
| 16 | # 创建网址到名称的映射字典 |
| 17 | url_to_key_map = {} |
| 18 | if origin: |
| 19 | for group in origin: |
| 20 | for item in group.get("items", []): |
| 21 | if "val" in item and "key" in item: |
| 22 | # 去除可能存在的反引号 |
| 23 | val = item["val"].replace("`", "").strip() |
| 24 | url_to_key_map[val] = item["key"] |
| 25 | |
| 26 | for folder in emoji_folders: |
| 27 | if not os.path.isdir(folder): |
| 28 | print(f"警告: {folder} 不是一个文件夹,已跳过") |
| 29 | continue |
| 30 | |
| 31 | emoji_group = { |
| 32 | "name": folder, |
| 33 | "type": "image", |
| 34 | "items": [] |
| 35 | } |
| 36 | |
| 37 | # 获取文件夹中的所有文件 |
| 38 | files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))] |
| 39 | |
| 40 | for file in files: |
| 41 | # 获取文件名(不带扩展名) |
| 42 | filename_without_ext = os.path.splitext(file)[0] |
| 43 | |
| 44 | # 构建完整URL |
| 45 | full_url = f"{base_url}/{folder}/{file}" |
| 46 | |
| 47 | # 检查是否在原始数据中存在该URL,如果存在则使用原始key |
| 48 | key = url_to_key_map.get(full_url, filename_without_ext) |
| 49 | |
| 50 | # 创建表情项 |
| 51 | emoji_item = { |
| 52 | "key": key, |
| 53 | "val": full_url |
| 54 | } |
| 55 | |
| 56 | emoji_group["items"].append(emoji_item) |
| 57 | |
| 58 | if emoji_group["items"]: # 只添加非空的表情组 |
| 59 | result.append(emoji_group) |
| 60 | |
| 61 | # 确保输出目录存在 |
| 62 | os.makedirs(os.path.dirname(output_path), exist_ok=True) |
| 63 | |
| 64 | # 写入 JSON 文件 |
| 65 | with open(output_path, 'w', encoding='utf-8') as f: |
| 66 | json.dump(result, f, ensure_ascii=False, indent=2) |
| 67 | |
| 68 | print(f"表情包 JSON 文件已生成: {output_path}") |
| 69 | |
| 70 | if __name__ == "__main__": |
| 71 | base_url = "https://jsd.example.com/gh/willow-god/owo/" |
| 72 | folders = ["liushen", "blobcat", "linedog", "bilibili"] |
| 73 | origin_json = ".json/artalk-emoji.json" |
| 74 | output = ".json/artalk-emoji.json" |
| 75 | |
| 76 | # 加载原始表情包数据(如果存在) |
| 77 | origin_data = None |
| 78 | try: |
| 79 | with open(origin_json, 'r', encoding='utf-8') as f: |
| 80 | origin_data = json.load(f) |
| 81 | print(f"已加载原始表情包数据: {origin_json}") |
| 82 | except FileNotFoundError: |
| 83 | print(f"未找到原始表情包数据文件: {origin_json}") |
| 84 | except json.JSONDecodeError: |
| 85 | print(f"原始表情包数据文件格式错误: {origin_json}") |
| 86 | |
| 87 | generate_artalk_emojis(base_url, folders, output, origin_data) |
generate-owo-twikoo.py
· 3.7 KiB · Python
Raw
import os
import json
def generate_twikoo_emojis(base_url, emoji_folders, output_path='.json/twikoo-emojis.json', origin=None):
"""
生成 Twikoo 表情包 JSON 文件
参数:
base_url: 基础 URL
emoji_folders: 包含表情包的文件夹列表
output_path: 输出 JSON 文件的路径
origin: 原始表情包数据,包含网址到名称的映射关系
"""
result = {}
# 创建网址到名称的映射字典
url_to_text_map = {}
if origin:
for category, data in origin.items():
if "container" in data:
for item in data["container"]:
if "icon" in item and "text" in item:
# 从 icon 中提取 URL
import re
url_match = re.search(r"src=['\"]([^'\"]+)['\"]", item["icon"])
if url_match:
url = url_match.group(1).replace("`", "").strip()
url_to_text_map[url] = item["text"]
for folder in emoji_folders:
if not os.path.isdir(folder):
print(f"警告: {folder} 不是一个文件夹,已跳过")
continue
# 为每个文件夹创建一个类别
category_name = folder
# 可以根据文件夹名称自定义类别显示名称
display_names = {
"blobcat": "可爱猫",
"linedog": "线条狗",
"bilibili": "小电视",
"liushen": "流沙",
# 可以添加更多映射
}
category_display_name = display_names.get(folder, folder)
emoji_category = {
"type": "image",
"container": []
}
# 获取文件夹中的所有文件
files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))]
for file in files:
# 获取文件名(不带扩展名)
filename_without_ext = os.path.splitext(file)[0]
# 构建完整URL
full_url = f"{base_url}/{folder}/{file}"
# 检查是否在原始数据中存在该URL,如果存在则使用原始text
text = url_to_text_map.get(full_url, f"{filename_without_ext}")
# 创建表情项
emoji_item = {
"text": text,
"icon": f"<img src='{full_url}'>"
}
emoji_category["container"].append(emoji_item)
if emoji_category["container"]: # 只添加非空的表情组
result[category_display_name] = emoji_category
# 确保输出目录存在
os.makedirs(os.path.dirname(output_path), exist_ok=True)
# 写入 JSON 文件
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(result, f, ensure_ascii=False, indent=2)
print(f"Twikoo 表情包 JSON 文件已生成: {output_path}")
if __name__ == "__main__":
base_url = "https://jsd.example.com/gh/willow-god/owo/"
folders = ["liushen", "blobcat", "linedog", "bilibili"]
origin_json = ".json/twikoo.json"
output = ".json/twikoo-emoji.json"
# 加载原始表情包数据(如果存在)
origin_data = None
try:
with open(origin_json, 'r', encoding='utf-8') as f:
origin_data = json.load(f)
print(f"已加载原始表情包数据: {origin_json}")
except FileNotFoundError:
print(f"未找到原始表情包数据文件: {origin_json}")
except json.JSONDecodeError:
print(f"原始表情包数据文件格式错误: {origin_json}")
generate_twikoo_emojis(base_url, folders, output, origin_data)
| 1 | import os |
| 2 | import json |
| 3 | |
| 4 | def generate_twikoo_emojis(base_url, emoji_folders, output_path='.json/twikoo-emojis.json', origin=None): |
| 5 | """ |
| 6 | 生成 Twikoo 表情包 JSON 文件 |
| 7 | |
| 8 | 参数: |
| 9 | base_url: 基础 URL |
| 10 | emoji_folders: 包含表情包的文件夹列表 |
| 11 | output_path: 输出 JSON 文件的路径 |
| 12 | origin: 原始表情包数据,包含网址到名称的映射关系 |
| 13 | """ |
| 14 | result = {} |
| 15 | |
| 16 | # 创建网址到名称的映射字典 |
| 17 | url_to_text_map = {} |
| 18 | if origin: |
| 19 | for category, data in origin.items(): |
| 20 | if "container" in data: |
| 21 | for item in data["container"]: |
| 22 | if "icon" in item and "text" in item: |
| 23 | # 从 icon 中提取 URL |
| 24 | import re |
| 25 | url_match = re.search(r"src=['\"]([^'\"]+)['\"]", item["icon"]) |
| 26 | if url_match: |
| 27 | url = url_match.group(1).replace("`", "").strip() |
| 28 | url_to_text_map[url] = item["text"] |
| 29 | |
| 30 | for folder in emoji_folders: |
| 31 | if not os.path.isdir(folder): |
| 32 | print(f"警告: {folder} 不是一个文件夹,已跳过") |
| 33 | continue |
| 34 | |
| 35 | # 为每个文件夹创建一个类别 |
| 36 | category_name = folder |
| 37 | # 可以根据文件夹名称自定义类别显示名称 |
| 38 | display_names = { |
| 39 | "blobcat": "可爱猫", |
| 40 | "linedog": "线条狗", |
| 41 | "bilibili": "小电视", |
| 42 | "liushen": "流沙", |
| 43 | # 可以添加更多映射 |
| 44 | } |
| 45 | |
| 46 | category_display_name = display_names.get(folder, folder) |
| 47 | |
| 48 | emoji_category = { |
| 49 | "type": "image", |
| 50 | "container": [] |
| 51 | } |
| 52 | |
| 53 | # 获取文件夹中的所有文件 |
| 54 | files = [f for f in os.listdir(folder) if os.path.isfile(os.path.join(folder, f))] |
| 55 | |
| 56 | for file in files: |
| 57 | # 获取文件名(不带扩展名) |
| 58 | filename_without_ext = os.path.splitext(file)[0] |
| 59 | |
| 60 | # 构建完整URL |
| 61 | full_url = f"{base_url}/{folder}/{file}" |
| 62 | |
| 63 | # 检查是否在原始数据中存在该URL,如果存在则使用原始text |
| 64 | text = url_to_text_map.get(full_url, f"{filename_without_ext}") |
| 65 | |
| 66 | # 创建表情项 |
| 67 | emoji_item = { |
| 68 | "text": text, |
| 69 | "icon": f"<img src='{full_url}'>" |
| 70 | } |
| 71 | |
| 72 | emoji_category["container"].append(emoji_item) |
| 73 | |
| 74 | if emoji_category["container"]: # 只添加非空的表情组 |
| 75 | result[category_display_name] = emoji_category |
| 76 | |
| 77 | # 确保输出目录存在 |
| 78 | os.makedirs(os.path.dirname(output_path), exist_ok=True) |
| 79 | |
| 80 | # 写入 JSON 文件 |
| 81 | with open(output_path, 'w', encoding='utf-8') as f: |
| 82 | json.dump(result, f, ensure_ascii=False, indent=2) |
| 83 | |
| 84 | print(f"Twikoo 表情包 JSON 文件已生成: {output_path}") |
| 85 | |
| 86 | if __name__ == "__main__": |
| 87 | base_url = "https://jsd.example.com/gh/willow-god/owo/" |
| 88 | folders = ["liushen", "blobcat", "linedog", "bilibili"] |
| 89 | origin_json = ".json/twikoo.json" |
| 90 | output = ".json/twikoo-emoji.json" |
| 91 | |
| 92 | # 加载原始表情包数据(如果存在) |
| 93 | origin_data = None |
| 94 | try: |
| 95 | with open(origin_json, 'r', encoding='utf-8') as f: |
| 96 | origin_data = json.load(f) |
| 97 | print(f"已加载原始表情包数据: {origin_json}") |
| 98 | except FileNotFoundError: |
| 99 | print(f"未找到原始表情包数据文件: {origin_json}") |
| 100 | except json.JSONDecodeError: |
| 101 | print(f"原始表情包数据文件格式错误: {origin_json}") |
| 102 | |
| 103 | generate_twikoo_emojis(base_url, folders, output, origin_data) |