diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-16 17:44:47 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-16 17:44:47 +0100 |
| commit | a81ad9738e9013557b2bd3cbdd7014d981f032fe (patch) | |
| tree | ebe846a59dbc99f22ff2e021c293f39e24764bb2 /deckit | |
| parent | df7b5062118467dc02d3baade9a6b74390c050ba (diff) | |
| download | deck-it-a81ad9738e9013557b2bd3cbdd7014d981f032fe.tar.gz deck-it-a81ad9738e9013557b2bd3cbdd7014d981f032fe.zip | |
feat(xbox): one games list with installed badges
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/modules/xbox.py | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py index 7b3da3d..9254f99 100644 --- a/deckit/modules/xbox.py +++ b/deckit/modules/xbox.py @@ -149,11 +149,30 @@ def summarize_consoles(r: dict) -> list: def summarize_apps(r: dict) -> list: - """A console's installed titles, biggest first.""" - apps = [{"name": a.get("name"), "game": a.get("contentType") == "Game", "size": a.get("sizeInBytes") or 0, - "version": a.get("version"), "updated": a.get("updateTime") or a.get("installTime"), - "last": a.get("lastActiveTime")} for a in r.get("result") or []] - return sorted(apps, key=lambda a: -a["size"]) + """A console's installed games and apps (DLC is not a title of its own).""" + return [{"id": str(a["titleId"]) if a.get("titleId") else None, + "pfn": (a.get("aumid") or "").split("!")[0] or None, + "name": a.get("name"), "size": a.get("sizeInBytes") or 0, "version": a.get("version"), + "updated": a.get("updateTime") or a.get("installTime"), "last": a.get("lastActiveTime")} + for a in r.get("result") or [] if a.get("contentType") != "Dlc"] + + +def merge_installed(titles: list, apps: dict) -> list: + """The titles, each marked with what is installed of it on any console, + most recently played first.""" + by = {} + for console_apps in apps.values(): + for a in console_apps: + for k in (a["id"], a["pfn"]): + if k: + by.setdefault(k, a) + out = [] + for t in titles: + a = by.get(t["id"]) or by.get(t.get("pfn")) + inst = {"size": a["size"], "version": a["version"], "updated": a["updated"]} if a else None + last = max(filter(None, (t["last"], a and a["last"])), default=None) + out.append({**t, "installed": inst, "last": last}) + return sorted(out, key=lambda t: t["last"] or "", reverse=True) def minutes_played(r: dict) -> dict: @@ -171,7 +190,8 @@ def summarize_titles(r: dict, minutes: dict) -> list: for t in r.get("titles") or []: a = t.get("achievement") or {} tid = str(t["titleId"]) - out.append({"id": tid, "name": t.get("name"), "type": t.get("type"), "cover": t.get("displayImage"), + out.append({"id": tid, "pfn": t.get("pfn"), "name": t.get("name"), "type": t.get("type"), + "cover": t.get("displayImage"), "last": (t.get("titleHistory") or {}).get("lastTimePlayed"), "achievements": {"done": a.get("currentAchievements", 0), "total": a.get("totalAchievements", 0), "score": a.get("currentGamerscore", 0), "max": a.get("totalGamerscore", 0), @@ -379,28 +399,38 @@ class Xbox: xuid = self.auth["xuid"] def titles(): - history = self.api(TITLEHUB.format(xuid) + f"titlehistory/decoration/achievement,image?maxItems={TITLES}", - 2, extra=HUB) - ids = [str(t["titleId"]) for t in history.get("titles") or []] + """The recent titles plus every installed one, as one list.""" + found = list(self.api(TITLEHUB.format(xuid) + f"titlehistory/decoration/achievement,image?maxItems={TITLES}", + 2, extra=HUB).get("titles") or []) + known = {str(t["titleId"]) for t in found} | {t.get("pfn") for t in found} + apps = [a for v in (self.data.get("apps") or {}).values() for a in v] + pfns = sorted({a["pfn"] for a in apps if a["pfn"] and a["id"] not in known and a["pfn"] not in known}) + if pfns: + try: + found += self.api(TITLEHUB.format(xuid) + "batch/decoration/achievement,image", 2, + {"pfns": pfns, "windowsPhoneProductIds": []}, HUB).get("titles") or [] + except HttpError: + pass # installed titles without a cover; the recent ones still show + ids = [str(t["titleId"]) for t in found] try: minutes = minutes_played(self.api(USERSTATS, 2, { "arrangebyfield": "xuid", "xuids": [xuid], "stats": [{"name": "MinutesPlayed", "titleId": i} for i in ids]})) if ids else {} except HttpError: minutes = {} - out = summarize_titles(history, minutes) + out = merge_installed(summarize_titles({"titles": found}, minutes), self.data.get("apps") or {}) self.types.update({t["id"]: t["type"] for t in out}) return out parts = { "profile": lambda: summarize_profile(self.api(PROFILE, 3)), - "titles": titles, - "achievements": lambda: summarize_achievements(self.api(ACHIEVEMENTS.format(xuid), 2)), - "friends": lambda: summarize_friends(self.api(FRIENDS, 7)), - # console id -> installed titles + # console id -> installed titles; read before "titles", which merges them in "apps": lambda: {c["id"]: summarize_apps(self.api( XCCS + "/lists/installedApps?deviceId=" + urllib.parse.quote(c["id"]), 4, extra=SG)) for c in self.data.get("consoles") or []}, + "titles": titles, + "achievements": lambda: summarize_achievements(self.api(ACHIEVEMENTS.format(xuid), 2)), + "friends": lambda: summarize_friends(self.api(FRIENDS, 7)), } for key, read in parts.items(): try: |
