From 093c4b58dfed97dd0564e87c9ebe3bb0bd057598 Mon Sep 17 00:00:00 2001 From: arcnmx Date: Wed, 17 Jul 2024 09:57:43 -0700 Subject: [PATCH] feat(octoprint): timelapse uris --- nixos/octoprint.nix | 2 +- .../octoprint/octorant-timelapse-uri.patch | 33 +++++++++++++++++++ packages/octoprint/octorant.nix | 4 +++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/octoprint/octorant-timelapse-uri.patch diff --git a/nixos/octoprint.nix b/nixos/octoprint.nix index bf0694f6..4fdbb01f 100644 --- a/nixos/octoprint.nix +++ b/nixos/octoprint.nix @@ -115,7 +115,7 @@ in { timelapse_done = { enabled = true; # TODO: movie_basename needs uri encoding if it contains spaces .-. - message = "Timelapse for {gcode}: https://print.${domain}/downloads/timelapse/{movie_basename}"; + message = "Timelapse for {gcode}: [{movie_basename}](https://print.${domain}/downloads/timelapse/{movie_basename_uri})"; media = media.none; }; timelapse_failed.media = media.none; diff --git a/packages/octoprint/octorant-timelapse-uri.patch b/packages/octoprint/octorant-timelapse-uri.patch new file mode 100644 index 00000000..2fc0c6ed --- /dev/null +++ b/packages/octoprint/octorant-timelapse-uri.patch @@ -0,0 +1,33 @@ +diff --git a/octoprint_octorant/__init__.py b/octoprint_octorant/__init__.py +--- a/octoprint_octorant/__init__.py ++++ b/octoprint_octorant/__init__.py +@@ -4,6 +4,7 @@ from __future__ import absolute_import + import octoprint.plugin + import octoprint.settings + import octoprint.util ++import urllib.parse + import subprocess + import datetime + import time +@@ -453,6 +454,8 @@ class OctorantPlugin( + # Alter a bit the payload to offer more variables + if "time" in data: + data["time_formatted"] = str(datetime.timedelta(seconds=int(data["time"]))) ++ if "movie_basename" in data: ++ data["movie_basename_uri"] = urllib.parse.quote(data["movie_basename"]) + + self._logger.debug( + "Available variables for event " + eventID + ": " + ", ".join(list(data)) +diff --git a/octoprint_octorant/events.py b/octoprint_octorant/events.py +index 0c53f88..9e7b19c 100644 +--- a/octoprint_octorant/events.py ++++ b/octoprint_octorant/events.py +@@ -135,7 +135,7 @@ EVENTS = { + "enabled": False, + "media": "timelapse", + "message": "🎥 Timelapse has been created: {movie_basename}", +- "variables": ["gcode", "movie", "movie_basename", "movie_prefix"], ++ "variables": ["gcode", "movie", "movie_basename", "movie_basename_uri", "movie_prefix"], + }, + "timelapse_failed": { + "enabled": False, diff --git a/packages/octoprint/octorant.nix b/packages/octoprint/octorant.nix index 834c57fc..5fc6f6b7 100644 --- a/packages/octoprint/octorant.nix +++ b/packages/octoprint/octorant.nix @@ -14,6 +14,10 @@ in buildPlugin { sha256 = "sha256-gP79zlJ8gdtpddXOJIMhouSbwXnrSf+c1bURkN/7jvw="; }; + patches = [ + ./octorant-timelapse-uri.patch + ]; + propagatedBuildInputs = with python3Packages; [ pillow ];