Add timer to yt-dlp subscribe functionality

This commit is contained in:
Yan Lin 2025-09-21 21:51:17 +02:00
parent ed4fd5293f
commit 89c58a371e
2 changed files with 45 additions and 4 deletions

View file

@ -15,10 +15,12 @@
subscriptions = { subscriptions = {
enable = true; enable = true;
feeds = [ feeds = [
# Example feed - replace with your actual subscriptions "https://www.youtube.com/feeds/videos.xml?channel_id=UCm22FAXZMw1BaWeFszZxUKw"
"https://www.youtube.com/feeds/videos.xml?channel_id=UCovVc-qqwYp8oqwO3Sdzx7w" "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;
}; };
}; };

View file

@ -39,10 +39,17 @@ in
interval = mkOption { interval = mkOption {
type = types.str; type = types.str;
default = "hourly"; default = "hourly";
example = "*-*-* *:30:00"; example = "*-*-* */4:00:00";
description = "Systemd timer schedule for checking subscriptions"; 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 { maxVideosPerFeed = mkOption {
type = types.int; type = types.int;
default = 5; 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" ];
};
};
}; };
} }