aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AGENTS.md7
-rw-r--r--deckit/modules/xbox.py21
-rw-r--r--static/deck.css13
-rw-r--r--static/modules/xbox.js45
-rw-r--r--tests/test_xbox.py18
5 files changed, 99 insertions, 5 deletions
diff --git a/AGENTS.md b/AGENTS.md
index c685edd..ca899e5 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -102,7 +102,12 @@ Keep the server dependency-free apart from that one package.
titles (`xccs` installedApps) every 10 min and on a title change; an
endpoint that refuses keeps its last data. Installed titles join the
recent ones in one games list (titlehub batch by pfn for those not
- recent), marked `installed`, most recently played first. Xbox Live has no system
+ recent), marked `installed`, most recently played first. The slow read also
+ takes the uploaded screenshots and clips (mediahub `screenshots`/`gameclips`
+ search, `OwnerXuid eq <xuid>`); their CDN URIs are signed, so the tab shows
+ and downloads them straight from Microsoft, in a `<dialog closedby="any">`
+ outside the redrawn part. Only captures the console uploaded appear; Xbox
+ keeps them 90 days (`expirationDate`). Xbox Live has no system
software version. The profile and console cards share `.xb-hero`, whose
background is the gamerpic (Xbox's own profile background is it blurred)
in greyscale, blurred and multiplied over `--udt-accent` under a
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:
diff --git a/static/deck.css b/static/deck.css
index 1bebd1a..02c91aa 100644
--- a/static/deck.css
+++ b/static/deck.css
@@ -962,7 +962,18 @@ dialog.vm-sheet::backdrop { background: color-mix(in srgb, var(--udt-crust) 55%,
.xbox .xb-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.xbox .xb-game { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.xbox .xb-gcover { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--udt-surface0); }
-.xbox .xb-gname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.xbox .xb-cap { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
+.xbox .xb-ccover { aspect-ratio: 16 / 9; }
+.xbox dialog.xb-view { margin: auto; width: min(1100px, 94vw); max-height: 92vh; padding: 14px; border: 0;
+ border-radius: 18px; background: var(--udt-base); color: var(--udt-text); }
+.xbox .xb-vclose { position: absolute; top: 24px; right: 24px; border-radius: 50%; padding: 0;
+ background: color-mix(in srgb, var(--udt-crust) 70%, transparent); }
+.xbox dialog.xb-view[open] { position: fixed; display: flex; flex-direction: column; gap: 12px; }
+.xbox dialog.xb-view::backdrop { background: color-mix(in srgb, var(--udt-crust) 70%, transparent); }
+.xbox .xb-vmedia { width: 100%; max-height: 75vh; object-fit: contain; border-radius: 12px; background: var(--udt-crust); }
+.xbox .xb-vfoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
+.xbox .xb-vdl { display: inline-flex; align-items: center; padding: 0 18px; font-size: 1rem; font-weight: 600; text-decoration: none; }
+.xbox .xb-gname {font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xbox .xb-gmeta { color: var(--udt-subtext0); font-size: 0.857rem; }
.xbox .xb-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.xbox .xb-list { display: flex; flex-direction: column; gap: 8px; }
diff --git a/static/modules/xbox.js b/static/modules/xbox.js
index 7c569ed..094b1c0 100644
--- a/static/modules/xbox.js
+++ b/static/modules/xbox.js
@@ -208,6 +208,37 @@ function gameTile(t) {
return tile;
}
+// The viewer lives outside the redrawn part, so a data change leaves it open.
+// The links are signed CDN URIs; the CDN answers octet-stream, so the link downloads.
+function view(c, dlg) {
+ const media = c.kind === "clip" ? h("video", "xb-vmedia") : img(c.url, "xb-vmedia");
+ if (c.kind === "clip") Object.assign(media, { src: c.url, controls: true, autoplay: true, playsInline: true });
+ const a = h("a", "ib xb-vdl", "Download");
+ a.href = c.url;
+ a.download = `${c.id}.${c.kind === "clip" ? "mp4" : "png"}`;
+ a.referrerPolicy = "no-referrer";
+ const foot = h("div", "xb-vfoot");
+ foot.append(h("div", "xb-gmeta", [c.title, new Date(c.date).toLocaleString(),
+ c.expires ? `kept until ${new Date(c.expires).toLocaleDateString()}` : null].filter(Boolean).join(" · ")));
+ foot.append(a);
+ const close = h("button", "ib nf xb-vclose", "\u{F0156}");
+ close.setAttribute("aria-label", "Close");
+ close.onclick = () => dlg.close();
+ dlg.replaceChildren(media, foot, close);
+ dlg.onclose = () => dlg.replaceChildren(); // stops a clip still playing
+ dlg.showModal();
+}
+
+function captureTile(c, dlg) {
+ const tile = h("button", "xb-game xb-cap");
+ const art = h("div", "xb-gart");
+ art.append(img(c.thumb, "xb-gcover xb-ccover"));
+ if (c.kind === "clip") art.append(h("span", "xb-badge", `Clip · ${c.seconds ?? "?"} s`));
+ tile.append(art, h("div", "xb-gname", c.title ?? ""), h("div", "xb-gmeta", ago(c.date)));
+ tile.onclick = () => view(c, dlg);
+ return tile;
+}
+
function row(pic, title, sub, side, cls = "") {
const r = h("div", `xb-row ${cls}`);
const text = h("div", "xb-rtext");
@@ -240,7 +271,7 @@ function signIn(box, st) {
box.append(wrap);
}
-function render(box, st) {
+function render(box, st, dlg) {
box.textContent = "";
const p = st.profile ?? {};
const head = h("div", "xb-head");
@@ -267,6 +298,13 @@ function render(box, st) {
for (const t of st.titles ?? []) games.append(gameTile(t));
box.append(games);
+ if (st.captures?.length) {
+ box.append(h("div", "xb-section", "Captures"));
+ const caps = h("div", "xb-games");
+ for (const c of st.captures) caps.append(captureTile(c, dlg));
+ box.append(caps);
+ }
+
const lists = h("div", "xb-lists");
const ach = h("div", "xb-card xb-list");
ach.append(h("div", "xb-section", "Achievements"));
@@ -288,7 +326,8 @@ export default {
peek: (st) => sessionPeek(st),
mount(el) {
- el.innerHTML = '<div class="xbox"><div class="xb-off"></div><div class="xb-on"></div></div>';
+ el.innerHTML = '<div class="xbox"><div class="xb-off"></div><div class="xb-on"></div>' +
+ '<dialog class="xb-view" closedby="any"></dialog></div>';
},
update(st, el) {
@@ -315,7 +354,7 @@ export default {
on._key = key;
if (st.signed_in === false) signIn(on, st);
else if (st.loading) on.replaceChildren(h("div", "xb-loading", "Loading Xbox Live…"));
- else render(on, st);
+ else render(on, st, el.querySelector(".xb-view"));
}
const c = on.querySelector(".xb-clock");
if (c) c.textContent = clock(st.session);
diff --git a/tests/test_xbox.py b/tests/test_xbox.py
index 0bcc883..a05ba60 100644
--- a/tests/test_xbox.py
+++ b/tests/test_xbox.py
@@ -63,6 +63,13 @@ FRIENDS = {"people": [
{"gamertag": "zed", "displayPicRaw": "z.png", "presenceState": "Offline", "presenceText": "Offline", "isFavorite": True},
{"gamertag": "bob", "displayPicRaw": "b.png", "presenceState": "Online", "presenceText": "Some Game", "isFavorite": False},
{"gamertag": "amy", "displayPicRaw": "a.png", "presenceState": "Online", "presenceText": "Home", "isFavorite": True}]}
+SHOTS = {"values": [{"contentId": "S1", "titleName": "Some Game", "captureDate": "2026-11-22T14:08:54Z",
+ "expirationDate": "2027-02-20T14:09:07Z", "contentLocators": [
+ {"locatorType": "Download", "uri": "https://cdn.example.org/s1.png?sig=x"},
+ {"locatorType": "Thumbnail_Large", "uri": "https://cdn.example.org/s1_t.png"}]}]}
+CLIPS = {"values": [{"contentId": "C1", "titleName": "Some Game", "captureDate": "2026-11-23T10:00:00Z",
+ "durationInSeconds": 30, "contentLocators": [{"locatorType": "Download", "uri": "https://cdn.example.org/c1.mp4"}]},
+ {"contentId": "C2", "contentLocators": []}]}
XSTS = {"Token": "XT", "DisplayClaims": {"xui": [{"uhs": "UHS", "xid": "1"}]}}
@@ -90,6 +97,8 @@ class Fake:
"/commands": {"status": {"errorCode": "OK"}, "opId": "op"},
"/lists/installedApps": APPS,
"/titles/batch/": BATCH,
+ "mediahub.xboxlive.com/screenshots": SHOTS,
+ "mediahub.xboxlive.com/gameclips": CLIPS,
}
self.answers.update(over)
@@ -212,6 +221,13 @@ class Summaries(unittest.TestCase):
def test_friends_online_then_favourite_then_name(self):
self.assertEqual([f["gamertag"] for f in xb.summarize_friends(FRIENDS)], ["amy", "bob", "zed"])
+ def test_captures_newest_first_without_a_download_skipped(self):
+ c = xb.summarize_captures(SHOTS, CLIPS)
+ self.assertEqual([(x["id"], x["kind"]) for x in c], [("C1", "clip"), ("S1", "shot")])
+ self.assertEqual((c[1]["thumb"], c[1]["url"]),
+ ("https://cdn.example.org/s1_t.png", "https://cdn.example.org/s1.png?sig=x"))
+ self.assertEqual(c[0]["seconds"], 30)
+
class Login(Base):
def test_no_client_id_refuses(self):
@@ -269,6 +285,8 @@ class Tick(Base):
self.assertEqual(st["titles"][0]["minutes"], 185)
self.assertEqual(st["achievements"][0]["score"], 15)
self.assertEqual(st["friends"][0]["gamertag"], "amy")
+ self.assertEqual(len(st["captures"]), 2)
+ self.assertEqual(self.fake.urls("mediahub")[0][1]["query"], "OwnerXuid eq 1")
self.assertIn("deviceId=CON1", self.fake.urls("/lists/installedApps")[0][0])
# the installed game missing from the recent ones comes from the batch, by pfn
self.assertEqual(self.fake.urls("/titles/batch/")[0][1]["pfns"], ["Old.Game_x"])