From 618e4580240c71a7ac866649e01439e75ef4d6a6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 23 Aug 2024 23:36:43 +0200 Subject: ... --- accounts/gkleen@sif/hyprland.nix | 4 +++ accounts/gkleen@sif/systemd.nix | 55 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) (limited to 'accounts') diff --git a/accounts/gkleen@sif/hyprland.nix b/accounts/gkleen@sif/hyprland.nix index 645a2f22..052f35b0 100644 --- a/accounts/gkleen@sif/hyprland.nix +++ b/accounts/gkleen@sif/hyprland.nix @@ -184,6 +184,10 @@ in { "CTRL, comma, exec, dunstctl history-pop" "$mainMod ALT, E, exec, emacsclient -c" + "$mainMod ALT, Y, exec, ${pkgs.writeShellScript "yt-dlp" '' + export PATH="${lib.makeBinPath (with pkgs; [ wl-clipboard-rs socat ])}:$PATH" + socat STDIO UNIX-CONNECT:"$XDG_RUNTIME_DIR"/yt-dlp.sock <<<$'{ "urls": ["'"$(wl-paste)"$'"] }' + ''}" ", XF86MonBrightnessUp, exec, lightctl -d -e4 -n1 up" ", XF86MonBrightnessDown, exec, lightctl -d -e4 -n1 down" 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 { ''}''; }; }; + "yt-dlp@" = { + Service = { + Type = "notify"; + RuntimeDirectory = "%N"; + StandardInput = "socket"; + StandardOutput = "journal"; + WatchdogSec = "10s"; + Environment = [ + "PATH=${lib.makeBinPath (with pkgs; [atomicparsley ffmpeg-headless rtmpdump])}" + ]; + ExecStart = pkgs.writers.writePython3 "yt-dlp" { + libraries = with pkgs.python3Packages; [ yt-dlp sdnotify ]; + } '' + import json + from yt_dlp import YoutubeDL, parse_options + from sys import stdin + from sdnotify import SystemdNotifier + from os import environ + from pathlib import Path + + + n = SystemdNotifier() + args = json.load(stdin) + ydl_opts = { + **parse_options().ydl_opts, + 'progress_hooks': [lambda _d: n.notify('WATCHDOG=1')], + 'postprocessor_hooks': [lambda _d: n.notify('WATCHDOG=1')], + 'progress_with_newline': True, + 'progress_delta': 5, + 'paths': { + 'home': str(Path.home() / 'media'), + 'temp': str(Path(environ['RUNTIME_DIRECTORY'])), + }, + **(args['params'] if 'params' in args else {}), + } + with YoutubeDL(ydl_opts) as ytdl: + n.notify('READY=1') + ytdl.download(args['urls']) + ''; + }; + }; } // listToAttrs (map ({host, port}: nameValuePair "proxy-to-autossh-socks@${toString port}" { Unit = { Requires = ["autossh-socks@${host}:${toString (port + 1)}.service" "proxy-to-autossh-socks@${toString port}.socket"]; @@ -294,7 +335,19 @@ in { Install = { WantedBy = ["default.target"]; }; - }) [8118 8120]); + }) [8118 8120]) // { + "yt-dlp" = { + Socket = { + SocketMode = "0600"; + Accept = true; + ListenStream = "%t/yt-dlp.sock"; + TriggerLimitIntervalSec = 0; + }; + Install = { + WantedBy = ["sockets.target"]; + }; + }; + }; timers = { sync-keepass = { Timer = { -- cgit v1.2.3