diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-28 09:04:21 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-28 09:04:21 +0100 |
| commit | 4b9d9661751379ea62ebdc2587dff20544c4ada4 (patch) | |
| tree | 2b118fb50a98c8e84e11cec39157bb244b0bca04 /deckit | |
| parent | 8397638ec70b23e05ef490e15f5d7c5c05e52d1f (diff) | |
| download | deck-it-4b9d9661751379ea62ebdc2587dff20544c4ada4.tar.gz deck-it-4b9d9661751379ea62ebdc2587dff20544c4ada4.zip | |
feat(xbox): mark captures saved on the PC, icon save button
A capture whose file is already in Pictures/Xbox or Videos/Xbox carries
`saved` and gets a check on its tile. The viewer keeps one icon button,
save to PC; the download to the tablet is gone. Deleting from Xbox Live
was tried and dropped: mediahub's DELETE answers 403 (errorCode 10401)
to a token from our own Azure app.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'deckit')
| -rw-r--r-- | deckit/modules/xbox.py | 28 |
1 files changed, 20 insertions, 8 deletions
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) |
