From 89c58a371e41fc982fbaf0ab899e1f00880a40fa Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Sun, 21 Sep 2025 21:51:17 +0200 Subject: [PATCH] Add timer to yt-dlp subscribe functionality --- hosts/nixos/hs/home.nix | 8 +++++--- modules/yt-dlp.nix | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/hosts/nixos/hs/home.nix b/hosts/nixos/hs/home.nix index d9a0807..83413dc 100644 --- a/hosts/nixos/hs/home.nix +++ b/hosts/nixos/hs/home.nix @@ -15,10 +15,12 @@ subscriptions = { enable = true; feeds = [ - # Example feed - replace with your actual subscriptions - "https://www.youtube.com/feeds/videos.xml?channel_id=UCovVc-qqwYp8oqwO3Sdzx7w" + "https://www.youtube.com/feeds/videos.xml?channel_id=UCm22FAXZMw1BaWeFszZxUKw" + "https://www.youtube.com/feeds/videos.xml?channel_id=UCYwVxWpjeKFWwu8TML-Te9A" ]; - maxVideosPerFeed = 1; # Start with just 3 videos per feed for testing + interval = "*-*-* 08:00:00"; + randomDelay = "1h"; + maxVideosPerFeed = 5; }; }; diff --git a/modules/yt-dlp.nix b/modules/yt-dlp.nix index 853a421..02eee8a 100644 --- a/modules/yt-dlp.nix +++ b/modules/yt-dlp.nix @@ -39,10 +39,17 @@ in interval = mkOption { type = types.str; default = "hourly"; - example = "*-*-* *:30:00"; + example = "*-*-* */4:00:00"; description = "Systemd timer schedule for checking subscriptions"; }; + randomDelay = mkOption { + type = types.str; + default = "0"; + example = "30m"; + description = "Random delay before running subscription check (e.g., '30m', '1h')"; + }; + maxVideosPerFeed = mkOption { type = types.int; default = 5; @@ -409,5 +416,37 @@ in ''} } ''; + + # Systemd user service and timer for subscription checking + systemd.user.services.yt-dlp-subscriptions = mkIf cfg.subscriptions.enable { + Unit = { + Description = "Check YouTube RSS subscriptions and download new videos"; + After = [ "network-online.target" ]; + Wants = [ "network-online.target" ]; + }; + + Service = { + Type = "oneshot"; + ExecStart = "${pkgs.bash}/bin/bash -lc 'check-youtube-subscriptions'"; + StandardOutput = "journal"; + StandardError = "journal"; + }; + }; + + systemd.user.timers.yt-dlp-subscriptions = mkIf cfg.subscriptions.enable { + Unit = { + Description = "Timer for YouTube subscription checks"; + }; + + Timer = { + OnCalendar = cfg.subscriptions.interval; + Persistent = true; + RandomizedDelaySec = cfg.subscriptions.randomDelay; + }; + + Install = { + WantedBy = [ "timers.target" ]; + }; + }; }; }