aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--AGENTS.md5
-rw-r--r--deckit/modules/xbox.py28
-rw-r--r--static/deck.css5
-rw-r--r--static/modules/xbox.js13
-rw-r--r--tests/test_xbox.py5
5 files changed, 37 insertions, 19 deletions
diff --git a/AGENTS.md b/AGENTS.md
index b86f6a0..bbee4bb 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -108,7 +108,10 @@ Keep the server dependency-free apart from that one package.
and downloads them straight from Microsoft, in a `<dialog closedby="any">`
outside the redrawn part. Its "Save to PC" is the `save` action: the PC
downloads a listed capture into `xdg-user-dir` PICTURES/Xbox or
- VIDEOS/Xbox and answers the path. Only captures the console uploaded appear; Xbox
+ VIDEOS/Xbox and answers the path; a capture whose file is there is
+ `saved` (a check on its tile). mediahub's DELETE refuses our token (403
+ `errorCode` 10401, tried 2026-11-28): it seems to want the Xbox app's
+ device and title tokens, so captures are deleted on the console. 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)
diff --git a/deckit/modules/xbox.py b/deckit/modules/xbox.py
index 5f9545a..8254e9c 100644
--- a/deckit/modules/xbox.py
+++ b/deckit/modules/xbox.py
@@ -28,6 +28,7 @@ The endpoints, headers and command bodies follow xbox-webapi-python; Microsoft
documents none of them for third parties.
"""
+import functools
import http.client
import json
import os
@@ -119,6 +120,7 @@ def _http(url, data=None, headers=None, timeout=10):
return json.loads(raw) if raw else {}
+@functools.cache
def user_dir(name: str) -> Path:
"""An XDG user directory (PICTURES, VIDEOS), else ~/Pictures or ~/Videos."""
try:
@@ -128,6 +130,14 @@ def user_dir(name: str) -> Path:
return Path(p) if p and Path(p) != Path.home() else Path.home() / name.title()
+def save_path(c: dict) -> Path:
+ """Where save puts a capture: <title> <capture date>.png|mp4."""
+ clip = c["kind"] == "clip"
+ name = " ".join(filter(None, [c.get("title"), (c.get("date") or c["id"])[:19].replace(":", "-")]))
+ name = "".join(ch if ch.isalnum() or ch in " -_.T" else "_" for ch in name).strip(" .")
+ return user_dir("VIDEOS" if clip else "PICTURES") / "Xbox" / f"{name}.{'mp4' if clip else 'png'}"
+
+
def foreground(presence: dict) -> dict | None:
"""The title filling a console's screen, if any."""
for dev in presence.get("devices") or []:
@@ -409,8 +419,9 @@ class Xbox:
return {"signed_in": False, "login": self._login_view()}
if "presence" not in self.data:
return {"signed_in": True, "offline": self.offline, "reason": self.reason, "loading": not self.offline}
+ caps = [{**c, "saved": save_path(c).exists()} for c in self.data.get("captures") or []]
return {"signed_in": True, "stale": self.offline, "reason": self.reason, **self.data,
- "playing": self.playing, "session": self.session}
+ "captures": caps, "playing": self.playing, "session": self.session}
# --- reads ----------------------------------------------------------
def read_fast(self):
@@ -551,16 +562,17 @@ class Xbox:
self.wake.set()
# --- saving a capture on the PC -------------------------------------
- def save(self, body: dict) -> dict:
- """Download a listed capture into the PC's Pictures/Xbox or
- Videos/Xbox; the answer names the file."""
+ def _capture(self, body: dict) -> dict:
c = next((c for c in self.data.get("captures") or [] if c["id"] == (body or {}).get("id")), None)
if c is None:
raise ModuleError("unknown capture")
- clip = c["kind"] == "clip"
- name = " ".join(filter(None, [c.get("title"), (c.get("date") or c["id"])[:19].replace(":", "-")]))
- name = "".join(ch if ch.isalnum() or ch in " -_.T" else "_" for ch in name).strip(" .")
- path = user_dir("VIDEOS" if clip else "PICTURES") / "Xbox" / f"{name}.{'mp4' if clip else 'png'}"
+ return c
+
+ def save(self, body: dict) -> dict:
+ """Download a listed capture into the PC's Pictures/Xbox or
+ Videos/Xbox; the answer names the file."""
+ c = self._capture(body)
+ path = save_path(c)
tmp = path.with_name("." + path.name + ".part")
try:
path.parent.mkdir(parents=True, exist_ok=True)
diff --git a/static/deck.css b/static/deck.css
index 6e46154..d080d4d 100644
--- a/static/deck.css
+++ b/static/deck.css
@@ -972,8 +972,9 @@ dialog.vm-sheet::backdrop { background: color-mix(in srgb, var(--udt-crust) 55%,
.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-vbtns { display: flex; gap: 8px; flex: none; }
-.xbox .xb-vdl { display: inline-flex; align-items: center; padding: 0 18px; font-size: 1rem; font-weight: 600; text-decoration: none; }
+.xbox .xb-vdl { display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; font-size: 1.4rem; }
+.xbox .xb-saved { position: absolute; top: 6px; right: 6px; display: grid; place-items: center; width: 1.6rem; height: 1.6rem;
+ border-radius: 999px; background: var(--udt-green); color: var(--udt-base); font-size: 1rem; }
.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; }
diff --git a/static/modules/xbox.js b/static/modules/xbox.js
index ad6eda2..1b58fb4 100644
--- a/static/modules/xbox.js
+++ b/static/modules/xbox.js
@@ -30,6 +30,7 @@ export function sessionPeek(st, store = globalThis.localStorage) {
// Nerd Font (Material Design) glyphs.
const G = {
+ save: "\u{F01DA}", check: "\u{F012C}",
xbox: "\u{F05B9}", power: "\u{F0425}", play: "\u{F040A}", pause: "\u{F03E4}",
vol_down: "\u{F075E}", vol_up: "\u{F075D}", mute: "\u{F0581}", unmute: "\u{F057E}",
};
@@ -213,15 +214,12 @@ function gameTile(t) {
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", "Tablet");
- a.href = c.url;
- a.download = `${c.id}.${c.kind === "clip" ? "mp4" : "png"}`;
- a.referrerPolicy = "no-referrer";
const meta = [c.title, new Date(c.date).toLocaleString(),
c.expires ? `kept until ${new Date(c.expires).toLocaleDateString()}` : null].filter(Boolean).join(" · ");
const info = h("div", "xb-gmeta", meta);
// The PC downloads it into Pictures/Xbox or Videos/Xbox; the answer names the file.
- const pc = h("button", "ib xb-vdl", "Save to PC");
+ const pc = h("button", "ib nf xb-vdl", G.save);
+ pc.setAttribute("aria-label", "Save to PC");
pc.onclick = async () => {
pc.disabled = true;
info.textContent = "Saving…";
@@ -237,9 +235,7 @@ function view(c, dlg) {
pc.disabled = false;
};
const foot = h("div", "xb-vfoot");
- const btns = h("div", "xb-vbtns");
- btns.append(pc, a);
- foot.append(info, btns);
+ foot.append(info, pc);
const close = h("button", "ib nf xb-vclose", "\u{F0156}");
close.setAttribute("aria-label", "Close");
close.onclick = () => dlg.close();
@@ -253,6 +249,7 @@ function captureTile(c, dlg) {
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`));
+ if (c.saved) art.append(h("span", "nf xb-saved", G.check));
tile.append(art, h("div", "xb-gname", c.title ?? ""), h("div", "xb-gmeta", ago(c.date)));
tile.onclick = () => view(c, dlg);
return tile;
diff --git a/tests/test_xbox.py b/tests/test_xbox.py
index 85146a4..62872af 100644
--- a/tests/test_xbox.py
+++ b/tests/test_xbox.py
@@ -430,6 +430,11 @@ class Save(Base):
xb.user_dir = old
self.assertEqual(path, d / "VIDEOS" / "Xbox" / "Some Game 2026-11-23T10-00-00.mp4")
self.assertEqual(path.read_bytes(), b"clip")
+ xb.user_dir = lambda name: d / name
+ try:
+ self.assertEqual([c["saved"] for c in x.state()["captures"]], [True, False])
+ finally:
+ xb.user_dir = old
class Commands(Base):