diff options
Diffstat (limited to 'accounts/gkleen@sif/systemd.nix')
-rw-r--r-- | accounts/gkleen@sif/systemd.nix | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/accounts/gkleen@sif/systemd.nix b/accounts/gkleen@sif/systemd.nix index 09d058de..b7bf902e 100644 --- a/accounts/gkleen@sif/systemd.nix +++ b/accounts/gkleen@sif/systemd.nix | |||
@@ -278,6 +278,47 @@ in { | |||
278 | ''}''; | 278 | ''}''; |
279 | }; | 279 | }; |
280 | }; | 280 | }; |
281 | "yt-dlp@" = { | ||
282 | Service = { | ||
283 | Type = "notify"; | ||
284 | RuntimeDirectory = "%N"; | ||
285 | StandardInput = "socket"; | ||
286 | StandardOutput = "journal"; | ||
287 | WatchdogSec = "10s"; | ||
288 | Environment = [ | ||
289 | "PATH=${lib.makeBinPath (with pkgs; [atomicparsley ffmpeg-headless rtmpdump])}" | ||
290 | ]; | ||
291 | ExecStart = pkgs.writers.writePython3 "yt-dlp" { | ||
292 | libraries = with pkgs.python3Packages; [ yt-dlp sdnotify ]; | ||
293 | } '' | ||
294 | import json | ||
295 | from yt_dlp import YoutubeDL, parse_options | ||
296 | from sys import stdin | ||
297 | from sdnotify import SystemdNotifier | ||
298 | from os import environ | ||
299 | from pathlib import Path | ||
300 | |||
301 | |||
302 | n = SystemdNotifier() | ||
303 | args = json.load(stdin) | ||
304 | ydl_opts = { | ||
305 | **parse_options().ydl_opts, | ||
306 | 'progress_hooks': [lambda _d: n.notify('WATCHDOG=1')], | ||
307 | 'postprocessor_hooks': [lambda _d: n.notify('WATCHDOG=1')], | ||
308 | 'progress_with_newline': True, | ||
309 | 'progress_delta': 5, | ||
310 | 'paths': { | ||
311 | 'home': str(Path.home() / 'media'), | ||
312 | 'temp': str(Path(environ['RUNTIME_DIRECTORY'])), | ||
313 | }, | ||
314 | **(args['params'] if 'params' in args else {}), | ||
315 | } | ||
316 | with YoutubeDL(ydl_opts) as ytdl: | ||
317 | n.notify('READY=1') | ||
318 | ytdl.download(args['urls']) | ||
319 | ''; | ||
320 | }; | ||
321 | }; | ||
281 | } // listToAttrs (map ({host, port}: nameValuePair "proxy-to-autossh-socks@${toString port}" { | 322 | } // listToAttrs (map ({host, port}: nameValuePair "proxy-to-autossh-socks@${toString port}" { |
282 | Unit = { | 323 | Unit = { |
283 | Requires = ["autossh-socks@${host}:${toString (port + 1)}.service" "proxy-to-autossh-socks@${toString port}.socket"]; | 324 | Requires = ["autossh-socks@${host}:${toString (port + 1)}.service" "proxy-to-autossh-socks@${toString port}.socket"]; |
@@ -294,7 +335,19 @@ in { | |||
294 | Install = { | 335 | Install = { |
295 | WantedBy = ["default.target"]; | 336 | WantedBy = ["default.target"]; |
296 | }; | 337 | }; |
297 | }) [8118 8120]); | 338 | }) [8118 8120]) // { |
339 | "yt-dlp" = { | ||
340 | Socket = { | ||
341 | SocketMode = "0600"; | ||
342 | Accept = true; | ||
343 | ListenStream = "%t/yt-dlp.sock"; | ||
344 | TriggerLimitIntervalSec = 0; | ||
345 | }; | ||
346 | Install = { | ||
347 | WantedBy = ["sockets.target"]; | ||
348 | }; | ||
349 | }; | ||
350 | }; | ||
298 | timers = { | 351 | timers = { |
299 | sync-keepass = { | 352 | sync-keepass = { |
300 | Timer = { | 353 | Timer = { |