about summary refs log tree commit diff stats
path: root/modules/by-name/yt
diff options
context:
space:
mode:
Diffstat (limited to 'modules/by-name/yt')
-rw-r--r--modules/by-name/yt/yt/config.toml2
-rwxr-xr-xmodules/by-name/yt/yt/external_commands_script.sh9
-rw-r--r--modules/by-name/yt/yt/input.conf14
-rw-r--r--modules/by-name/yt/yt/module.nix108
-rw-r--r--modules/by-name/yt/yt/mpv.conf1
5 files changed, 114 insertions, 20 deletions
diff --git a/modules/by-name/yt/yt/config.toml b/modules/by-name/yt/yt/config.toml
deleted file mode 100644
index 981481d9..00000000
--- a/modules/by-name/yt/yt/config.toml
+++ /dev/null
@@ -1,2 +0,0 @@
-[download]
-max_cache_size = "5 GiB"
diff --git a/modules/by-name/yt/yt/external_commands_script.sh b/modules/by-name/yt/yt/external_commands_script.sh
new file mode 100755
index 00000000..2e59e94a
--- /dev/null
+++ b/modules/by-name/yt/yt/external_commands_script.sh
@@ -0,0 +1,9 @@
+#! /usr/bin/env sh
+
+riverctl focus-output next
+
+alacritty --title "floating please" --command "$@"
+
+riverctl focus-output next
+
+# vim: ft=sh
diff --git a/modules/by-name/yt/yt/input.conf b/modules/by-name/yt/yt/input.conf
deleted file mode 100644
index 68dad824..00000000
--- a/modules/by-name/yt/yt/input.conf
+++ /dev/null
@@ -1,14 +0,0 @@
-c script-message yt-comments-external
-C script-message yt-comments-local
-
-d script-message yt-description-external
-D script-message yt-description-local
-
-WHEEL_LEFT playlist-prev
-WHEEL_RIGHT playlist-next
-
-q script-message yt-mark-watched
-Q script-message yt-mark-picked
-r script-message yt-check-new-videos
-
-P quit
diff --git a/modules/by-name/yt/yt/module.nix b/modules/by-name/yt/yt/module.nix
index b93feeb5..3ac59439 100644
--- a/modules/by-name/yt/yt/module.nix
+++ b/modules/by-name/yt/yt/module.nix
@@ -1,9 +1,111 @@
+# nixos-config - My current NixOS configuration
+#
+# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+# SPDX-License-Identifier: GPL-3.0-or-later
+#
+# This file is part of my nixos-config.
+#
+# You should have received a copy of the License along with this program.
+# If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
 {
   config,
   lib,
+  pkgs,
   ...
 }: let
   cfg = config.soispha.programs.yt;
+
+  mkConfig = (pkgs.formats.toml {}).generate;
+
+  mpvInputConfig = {
+    "c" = "script-message yt-comments-external";
+    "C" = "script-message yt-comments-local";
+
+    "d" = "script-message yt-description-external";
+    "D" = "script-message yt-description-local";
+
+    "t" = "script-message yt-thumbnail-external";
+    "I" = "script-message yt-info-external";
+
+    "WHEEL_LEFT" = "playlist-prev";
+    "WHEEL_RIGHT" = "playlist-next";
+
+    "q" = "script-message yt-mark-watched";
+    "Q" = "script-message yt-mark-picked";
+    "r" = "script-message yt-check-new-videos";
+
+    "P" = "quit";
+  };
+
+  mpvConf = {
+    "volume" = 75;
+  };
+
+  ytConfig = {
+    download = {
+      max_cache_size = "5 GiB";
+    };
+
+    commands = {
+      image_show = [
+        (lib.getExe
+          (pkgs.writeShellApplication {
+            name = "show_thumbnail";
+            text = ''
+              imv -w "floating please" "$1"
+            '';
+            runtimeInputs = [
+              pkgs.imv
+            ];
+
+            inheritPath = false;
+          }))
+      ];
+
+      external_spawn = [
+        (lib.getExe
+          (pkgs.writeShellApplication {
+            name = "start_external_command";
+            text = builtins.readFile ./external_commands_script.sh;
+            runtimeInputs = [
+              pkgs.river
+              pkgs.alacritty
+              pkgs.less
+            ];
+
+            inheritPath = false;
+          }))
+      ];
+
+      url_opener = ["qutebrowser-timesinks.youtube"];
+    };
+  };
+
+  inherit (lib) generators;
+  inherit (builtins) typeOf stringLength;
+
+  renderOption = option:
+    rec {
+      int = toString option;
+      float = int;
+      bool = lib.hm.booleans.yesNo option;
+      string = option;
+    }
+    .${
+      typeOf option
+    };
+
+  renderOptionValue = value: let
+    rendered = renderOption value;
+    length = toString (stringLength rendered);
+  in "%${length}%${rendered}";
+
+  renderOptions = generators.toKeyValue {
+    mkKeyValue = generators.mkKeyValueDefault {mkValueString = renderOptionValue;} "=";
+    listsAsDuplicateKeys = true;
+  };
+
+  renderBindings = bindings: lib.concatStringsSep "\n" (lib.mapAttrsToList (name: value: "${name} ${value}") bindings);
 in {
   options.soispha.programs.yt = {
     enable = lib.mkEnableOption "the yt cli client";
@@ -12,9 +114,9 @@ in {
   config = {
     home-manager.users.soispha = lib.mkIf cfg.enable {
       xdg.configFile = {
-        "yt/mpv.conf".source = ./mpv.conf;
-        "yt/mpv.input.conf".source = ./input.conf;
-        "yt/config.toml".source = ./config.toml;
+        "yt/mpv.conf".text = renderOptions mpvConf;
+        "yt/mpv.input.conf".text = renderBindings mpvInputConfig;
+        "yt/config.toml".source = mkConfig "config.toml" ytConfig;
       };
     };
   };
diff --git a/modules/by-name/yt/yt/mpv.conf b/modules/by-name/yt/yt/mpv.conf
deleted file mode 100644
index 52a40823..00000000
--- a/modules/by-name/yt/yt/mpv.conf
+++ /dev/null
@@ -1 +0,0 @@
-volume=75