2023-06-17 05:01:34 +00:00
|
|
|
import ujson as json
|
2023-06-26 10:24:19 +00:00
|
|
|
import os
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-17 05:01:34 +00:00
|
|
|
from core.utils.http import get_url, post_url
|
2023-06-26 10:24:19 +00:00
|
|
|
from .maimaidx_music import get_cover_len5_id
|
2023-06-17 05:01:34 +00:00
|
|
|
|
2023-07-14 06:15:46 +00:00
|
|
|
assets_path = os.path.abspath('./assets/maimai')
|
|
|
|
|
|
|
|
async def update_alias():
|
|
|
|
try:
|
|
|
|
url = "https://download.fanyu.site/maimai/alias_uc.json"
|
2023-07-23 07:32:53 +00:00
|
|
|
input_data = await get_url(url, 200, fmt='json')
|
|
|
|
|
|
|
|
output_data = {}
|
2023-07-23 08:22:30 +00:00
|
|
|
for key, values in input_data.items():
|
|
|
|
for value in values:
|
|
|
|
if value == "未找到":
|
|
|
|
continue
|
|
|
|
if value not in output_data:
|
|
|
|
output_data[value] = []
|
|
|
|
output_data[value].append(key)
|
|
|
|
output_data = {k: output_data[k] for k in sorted(output_data)}
|
2023-07-14 09:42:19 +00:00
|
|
|
|
|
|
|
file_path = os.path.join(assets_path, "mai_alias.json")
|
|
|
|
with open(file_path, 'w') as file:
|
2023-07-23 07:32:53 +00:00
|
|
|
json.dump(output_data, file)
|
2023-07-14 06:15:46 +00:00
|
|
|
except:
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def get_alias(msg, input, get_music=False):
|
|
|
|
file_path = os.path.join(assets_path, "mai_alias.json")
|
|
|
|
|
|
|
|
if not os.path.exists(file_path):
|
2023-07-14 06:18:05 +00:00
|
|
|
await msg.finish(msg.locale.t("maimai.message.alias.file_not_found", prefix=msg.prefixes[0]))
|
2023-07-14 06:15:46 +00:00
|
|
|
with open(file_path, 'r') as file:
|
|
|
|
data = json.load(file)
|
2023-06-16 15:15:47 +00:00
|
|
|
|
|
|
|
result = []
|
|
|
|
if get_music:
|
2023-06-19 16:37:14 +00:00
|
|
|
for alias, ids in data.items():
|
|
|
|
if input in ids:
|
|
|
|
result.append(alias)
|
2023-07-23 07:32:53 +00:00
|
|
|
else:
|
|
|
|
input = input.replace("_", " ")
|
|
|
|
if input in data:
|
|
|
|
result = data[input]
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-16 15:15:47 +00:00
|
|
|
return result
|
|
|
|
|
2023-06-17 04:39:47 +00:00
|
|
|
|
2023-06-19 16:37:14 +00:00
|
|
|
async def get_record(msg, payload):
|
|
|
|
url = f"https://www.diving-fish.com/api/maimaidxprober/query/player"
|
2023-06-17 05:01:34 +00:00
|
|
|
try:
|
2023-06-19 16:37:14 +00:00
|
|
|
data = await post_url(url,
|
|
|
|
data=json.dumps(payload),
|
|
|
|
status_code=200,
|
|
|
|
headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json')
|
2023-06-17 05:01:34 +00:00
|
|
|
except ValueError as e:
|
|
|
|
if str(e).startswith('400'):
|
2023-08-19 19:11:08 +00:00
|
|
|
if "qq" in payload:
|
2023-08-19 18:53:20 +00:00
|
|
|
await msg.finish(msg.locale.t("maimai.message.user_unbound"))
|
|
|
|
else:
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.user_not_found"))
|
2023-06-17 05:01:34 +00:00
|
|
|
if str(e).startswith('403'):
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.forbidden"))
|
2023-06-17 03:38:06 +00:00
|
|
|
|
2023-06-19 16:37:14 +00:00
|
|
|
return data
|
2023-06-16 15:15:47 +00:00
|
|
|
|
|
|
|
|
2023-06-19 16:37:14 +00:00
|
|
|
async def get_plate(msg, payload):
|
|
|
|
url = f"https://www.diving-fish.com/api/maimaidxprober/query/plate"
|
|
|
|
try:
|
|
|
|
data = await post_url(url,
|
|
|
|
data=json.dumps(payload),
|
|
|
|
status_code=200,
|
|
|
|
headers={'Content-Type': 'application/json', 'accept': '*/*'}, fmt='json')
|
|
|
|
except ValueError as e:
|
|
|
|
if str(e).startswith('400'):
|
2023-08-19 19:18:25 +00:00
|
|
|
if "qq" in payload:
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.user_unbound"))
|
|
|
|
else:
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.user_not_found"))
|
2023-06-19 16:37:14 +00:00
|
|
|
if str(e).startswith('403'):
|
|
|
|
await msg.finish(msg.locale.t("maimai.message.forbidden"))
|
2023-06-16 15:15:47 +00:00
|
|
|
|
2023-06-19 16:37:14 +00:00
|
|
|
return data
|
2023-06-26 10:24:19 +00:00
|
|
|
|
|
|
|
def get_cover(sid):
|
2023-06-27 15:10:08 +00:00
|
|
|
cover_url = f"https://www.diving-fish.com/covers/{get_cover_len5_id(sid)}.png"
|
2023-06-26 10:24:19 +00:00
|
|
|
cover_dir = f"./assets/maimai/static/mai/cover/"
|
|
|
|
cover_path = cover_dir + f'{get_cover_len5_id(sid)}.png'
|
2023-08-19 19:11:08 +00:00
|
|
|
if sid == '11364': #8-EM 的封面需要本地调用
|
2023-06-26 10:24:19 +00:00
|
|
|
return os.path.abspath(cover_path)
|
|
|
|
else:
|
2023-06-27 15:00:19 +00:00
|
|
|
return cover_url
|