aboutsummaryrefslogtreecommitdiffstats
path: root/deckit/modules/xbox.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-11-26 11:16:40 +0100
committerDanilo M. <danix@danix.xyz>2026-11-26 11:16:40 +0100
commitd842b3c49fe4c03993f32fb9bebbef954c54675d (patch)
treee88f36e59793104cf220642ad792ca8df3a9a392 /deckit/modules/xbox.py
parent6496d0660abf781ff2a76f97f9a5c03034d6cf45 (diff)
downloaddeck-it-d842b3c49fe4c03993f32fb9bebbef954c54675d.tar.gz
deck-it-d842b3c49fe4c03993f32fb9bebbef954c54675d.zip
feat(xbox): list, view and download uploaded captures
The slow read also searches mediahub for the user's screenshots and game clips. Their CDN URIs are signed, so the tab shows thumbnails and opens a capture in a dialog (outside the redrawn part, so a data change leaves it open) with a download link and a close button, straight from Microsoft. Only captures the console uploaded appear; an in-game photo mode (e.g. Rockstar's) is not an Xbox capture. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'deckit/modules/xbox.py')
-rw-r--r--deckit/modules/xbox.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py
index 60f402e..fcf7d28 100644
--- a/deckit/modules/xbox.py
+++ b/deckit/modules/xbox.py
@@ -55,6 +55,7 @@ ACHIEVEMENTS = ("https://achievements.xboxlive.com/users/xuid({})/achievements"
"?orderBy=UnlockTime&unlockedOnly=true&maxItems=10")
FRIENDS = "https://peoplehub.xboxlive.com/users/me/people/friends/decoration/presenceDetail"
USERSTATS = "https://userstats.xboxlive.com/batch"
+MEDIAHUB = "https://mediahub.xboxlive.com/{}/search" # screenshots, gameclips
# titlehub answers only clients that name themselves; these are the Xbox app's.
HUB = {"x-xbl-client-name": "XboxApp", "x-xbl-client-type": "UWA", "x-xbl-client-version": "39.39.22001.0"}
SG = {"skillplatform": "RemoteManagement"}
@@ -76,6 +77,7 @@ QUICK, QUICK_FOR = 3, 30 # after a command: read every 3s for 30s, until the p
# ponytail: renewed by age, not by the XSTS NotAfter (about 16h); a 401 renews early too.
XSTS_FOR = 8 * 3600
TITLES = 12 # recent games shown
+CAPTURES = 24 # screenshots and clips shown, newest first
TOKEN = Path(os.environ.get("XDG_CONFIG_HOME") or Path.home() / ".config") / "deck-it" / "xbox-token.json"
STATUS = Path(os.environ.get("XDG_RUNTIME_DIR") or f"/run/user/{os.getuid()}") / "status.xbox"
@@ -213,6 +215,21 @@ def summarize_achievements(r: dict) -> list:
return out
+def summarize_captures(shots: dict, clips: dict) -> list:
+ """Uploaded screenshots and clips, newest first. The URIs are signed
+ (SAS): the tablet loads them with no auth, until they expire."""
+ out = []
+ for kind, r in (("shot", shots), ("clip", clips)):
+ for c in r.get("values") or []:
+ loc = {x.get("locatorType"): x.get("uri") for x in c.get("contentLocators") or []}
+ if loc.get("Download"):
+ out.append({"id": c.get("contentId"), "kind": kind, "title": c.get("titleName"),
+ "date": c.get("captureDate"), "expires": c.get("expirationDate"),
+ "seconds": c.get("durationInSeconds"),
+ "thumb": loc.get("Thumbnail_Large") or loc.get("Thumbnail_Small"), "url": loc["Download"]})
+ return sorted(out, key=lambda c: c["date"] or "", reverse=True)[:CAPTURES]
+
+
def summarize_friends(r: dict) -> list:
people = [{"gamertag": p.get("gamertag"), "pic": p.get("displayPicRaw"), "state": p.get("presenceState"),
"text": p.get("presenceText"), "favorite": bool(p.get("isFavorite"))}
@@ -433,6 +450,10 @@ class Xbox:
"titles": titles,
"achievements": lambda: summarize_achievements(self.api(ACHIEVEMENTS.format(xuid), 2)),
"friends": lambda: summarize_friends(self.api(FRIENDS, 7)),
+ # ponytail: the signed URIs are renewed by this 10 min read; the SAS
+ # lifetime is not in the URL, so a link could die first if it is short.
+ "captures": lambda: summarize_captures(*(self.api(MEDIAHUB.format(k), 3, {
+ "max": CAPTURES, "skip": 0, "query": f"OwnerXuid eq {xuid}"}) for k in ("screenshots", "gameclips"))),
}
for key, read in parts.items():
try: