1) 命名统一(服务端 API 名带 Get 的,脚本名与函数名一律带 get/Get)
- 26 个 api 脚本改名:userdata.py -> get_user_data.py 等
- 7 个 game_*.py -> get_game_*.py
- 38 个函数改名:UserData -> GetUserData 等
- upsert_snapshot.py -> get_need_user_data.py,
fetch_upsert_snapshot -> GetNeedUserData
- user_getter_common.fetch_all_pages -> get_all_pages
2) GetNeedUserData 抓到的数据自动落盘
- <工程根>/data/<userId>.json,新数据总是覆盖老数据
- 新增 save_user_data / load_user_data / user_data_path /
list_saved_user_ids / DATA_DIR / PROJECT_ROOT
- data/ 已加入 .gitignore
3) use_ticket.py(新)
- 读取账号当前持有的功能票,用 UpsertUserAll 消耗掉
- 依据:GetUserChargeApi 与 UpsertUserAllApi 的 userChargeList 格式相同;
真机实证 userChargeList.stock -1 + useTicketId + playCredit
- playCredit = 投币数 + 票的 creditNum(VOExtensions.cs:838-845)
4) reincarnate.py(新)
- 账号数据迁移(转生):A 的数据克隆到 B
- 每包最多 4 首(真机一局上限),包间用续关登录换新 loginId
续关依据:ContinueProcess.cs:403 -> PacketUserLogin(isContinue: true)
- playlog 从曲目记录反推合成(没有对应的 Get 接口)
自检 238 项全绿。
91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
get_user_music.py —— 取用户曲目成绩(GetUserMusicApi)
|
||
================================================================================
|
||
|
||
取玩家全部曲目的历史成绩归档(真机 739 组)。
|
||
|
||
对应接口:GetUserMusicApi
|
||
请求体 :UserMusicRequestVO(userId + nextIndex + maxCount=50)
|
||
响应 :{userId, nextIndex, userMusicList:[{userMusicDetailList:[...], length}]}
|
||
依据 :source/Assembly-CSharp/Net.VO.Mai2/UserMusicRequestVO.cs
|
||
source/Assembly-CSharp/Net.VO.Mai2/UserMusic.cs(外层按曲分组)
|
||
source/Assembly-CSharp/Net.VO.Mai2/GetUserMusicDetail.cs(内层按难度)
|
||
|
||
★ 响应是**两层嵌套**:外层每元素是一首歌,内层的 userMusicDetailList 才是
|
||
按 (musicId, level) 的成绩条目。取数时要摊平。
|
||
|
||
★ 回传 Upsert 时只回传本局玩的那一条(playCount +1),其余不动。
|
||
|
||
调用示例:
|
||
from api import GetUserMusicDetail, UserMusicDetailFlat
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any, Dict, List, Optional
|
||
|
||
from config import CLIENT_ID, TIMEOUT_MS
|
||
|
||
from .log_setup import log_info
|
||
from .maimai_net import MaimaiNetClient
|
||
from .user_getter_common import _get, UserMusicRequestVO, get_all_pages
|
||
|
||
|
||
def GetUserMusicDetail(
|
||
user_id: int,
|
||
*,
|
||
next_index: int = 0,
|
||
client_id: str = CLIENT_ID,
|
||
timeout_ms: Optional[int] = None,
|
||
client: Optional[MaimaiNetClient] = None,
|
||
) -> Dict[str, Any]:
|
||
"""
|
||
取用户曲目成绩(单页,对应 GetUserMusicApi)。
|
||
|
||
参数:
|
||
next_index: 分页起始索引(0 = 首页)
|
||
|
||
返回:
|
||
原始响应 dict,含 userMusicList(两层嵌套)
|
||
"""
|
||
log_info("取用户曲目成绩:user_id=" + str(user_id) + " next_index=" + str(next_index))
|
||
return _get(
|
||
"GetUserMusicApi",
|
||
UserMusicRequestVO(userId=user_id, nextIndex=next_index, maxCount=50),
|
||
user_id, client_id=client_id, timeout_ms=timeout_ms, client=client,
|
||
)
|
||
|
||
|
||
def GetUserMusicDetailAll(
|
||
user_id: int,
|
||
*,
|
||
client_id: str = CLIENT_ID,
|
||
timeout_ms: Optional[int] = None,
|
||
client: Optional[MaimaiNetClient] = None,
|
||
) -> Dict[str, Any]:
|
||
"""
|
||
取用户曲目成绩(自动翻页取全,已摊平成单层)。
|
||
|
||
返回:
|
||
{"userMusicList": [ {"musicId":..,"level":..,"playCount":..}, ... ]}
|
||
每元素是**单条 (musicId, level) 成绩**,不是按曲分组的嵌套结构。
|
||
"""
|
||
log_info("取用户曲目成绩(全量):user_id=" + str(user_id))
|
||
groups = get_all_pages(
|
||
"GetUserMusicApi", user_id, "userMusicList",
|
||
body_factory=lambda ni: UserMusicRequestVO(
|
||
userId=user_id, nextIndex=ni or 0, maxCount=50),
|
||
client_id=client_id, timeout_ms=timeout_ms, client=client,
|
||
)
|
||
flat: List[Dict[str, Any]] = []
|
||
for group in groups:
|
||
if isinstance(group, dict):
|
||
details = group.get("userMusicDetailList") or []
|
||
if isinstance(details, dict):
|
||
details = [details]
|
||
flat.extend(details)
|
||
log_info("曲目成绩获取完成:" + str(len(flat)) + " 条(原始 "
|
||
+ str(len(groups)) + " 组)")
|
||
return {"userMusicList": flat}
|