Initial commit: Add maimaiDX API web application with AimeDB scanning and logging features
This commit is contained in:
23
backend/MusicDB.py
Normal file
23
backend/MusicDB.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import rapidjson as json
|
||||
from Config import *
|
||||
from typing import Dict, Union
|
||||
|
||||
# 定义音乐数据库的类型注解
|
||||
MusicDBType = Dict[int, Dict[str, Union[int, str]]]
|
||||
|
||||
# 将 '__all__' 用于模块导出声明
|
||||
__all__ = ["musicDB"]
|
||||
|
||||
# 读取并解析 JSON 文件
|
||||
try:
|
||||
with open(musicDBPath, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
with open(musicDBPathFallback, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
except Exception:
|
||||
raise FileNotFoundError("musicDB.json 文件不存在!")
|
||||
|
||||
# 将 JSON 数据转换为指定格式的字典
|
||||
musicDB: MusicDBType = {int(k): v for k, v in data.items()}
|
||||
Reference in New Issue
Block a user