mirror of
https://github.com/Remik1r3n/maimaiDX-Api.git
synced 2025-05-20 10:37:28 +08:00
83 lines
3.3 KiB
Python
83 lines
3.3 KiB
Python
# 非常 All-in Boom 的 B50 更新实现。
|
||
|
||
from API_TitleServer import *
|
||
from HelperLogInOut import apiLogin, apiLogout, generateTimestamp
|
||
from Static_Settings import *
|
||
import json
|
||
from MusicDB import musicDB
|
||
from loguru import logger
|
||
|
||
def getMusicTitle(musicId: int) -> str:
|
||
'''从数据库获取音乐的标题'''
|
||
logger.debug(f"查询歌名: {musicId}")
|
||
musicInfo = musicDB.get(musicId)
|
||
if not musicInfo:
|
||
logger.warning(f"数据库里未找到此歌曲: {musicId}")
|
||
return "ERR_R_MUSIC_ID_NOT_IN_DATABASE"
|
||
musicName = musicInfo.get("name")
|
||
logger.debug(f"成功查询到歌名: {musicName}")
|
||
return musicName
|
||
|
||
def getUserMusicDetail(userId:int, nextIndex:int=0, maxCount:int=50) -> dict:
|
||
'''获取用户的成绩的API'''
|
||
data = json.dumps({
|
||
"userId": int(userId),
|
||
"nextIndex": nextIndex,
|
||
"maxCount": maxCount
|
||
})
|
||
return json.loads(apiSDGB(data, "GetUserMusicApi", userId))
|
||
|
||
def maimaiUserMusicDetailToDivingFish(userMusicDetailList: list) -> list:
|
||
'''舞萌的 UserMusicDetail 成绩格式转换成水鱼的格式'''
|
||
divingFishList = []
|
||
for currentMusicDetail in userMusicDetailList:
|
||
# 每一个乐曲都判断下是 DX 还是标准
|
||
if currentMusicDetail['musicId'] >= 10000:
|
||
notesType = 'DX'
|
||
else:
|
||
notesType = 'SD'
|
||
|
||
divingFishList.append({
|
||
'achievements': (currentMusicDetail['achievement'] / 10000), # 水鱼的成绩是 float 而非舞萌的 int
|
||
'title': (getMusicTitle(currentMusicDetail['musicId'])), # 水鱼用的是歌名而不是 ID(导致不得不用数据库处理转换
|
||
'type': notesType, # 我不理解这为什么不能在后端判断
|
||
'level_index': currentMusicDetail['level'],
|
||
'fc': currentMusicDetail['comboStatus'],
|
||
'fs': currentMusicDetail['syncStatus'],
|
||
'dxScore': currentMusicDetail['deluxscoreMax'],
|
||
})
|
||
return divingFishList
|
||
|
||
if __name__ == '__main__':
|
||
userId = testUid
|
||
currentLoginTimestamp = generateTimestamp()
|
||
loginResult = apiLogin(currentLoginTimestamp, userId)
|
||
|
||
if loginResult['returnCode'] != 1:
|
||
logger.info("登录失败")
|
||
exit()
|
||
try:
|
||
## Begin
|
||
userMusicDetailList_current = []
|
||
|
||
nextIndex:int|None = None # 初始化 nextIndex
|
||
while nextIndex != 0 or nextIndex is None: #只要还有nextIndex就一直获取获取
|
||
userMusicResponse = getUserMusicDetail(userId, nextIndex or 0)
|
||
nextIndex = userMusicResponse['nextIndex']
|
||
logger.info(f"NextIndex: {nextIndex}")
|
||
for currentMusic in userMusicResponse['userMusicList']:
|
||
for currentMusicDetail in currentMusic['userMusicDetailList']:
|
||
if not currentMusicDetail['playCount'] > 0:
|
||
continue
|
||
userMusicDetailList_current.append(currentMusicDetail)
|
||
print("---------------")
|
||
print(str(userMusicDetailList_current))
|
||
## End
|
||
#logger.info(apiLogout(currentLoginTimestamp, userId))
|
||
logger.warning("Now We Begin To Build DiveFish Data")
|
||
divingFishData = maimaiUserMusicDetailToDivingFish(userMusicDetailList_current)
|
||
logger.info(divingFishData)
|
||
finally:
|
||
#logger.error(f"Error: {e}")
|
||
logger.info(apiLogout(currentLoginTimestamp, userId))
|