diff --git a/hosts/nixos/hs/home.nix b/hosts/nixos/hs/home.nix index bf3e323..d9a0807 100644 --- a/hosts/nixos/hs/home.nix +++ b/hosts/nixos/hs/home.nix @@ -12,6 +12,14 @@ programs.yt-dlp-custom = { enable = true; downloadDir = "/mnt/storage/Media/web"; + subscriptions = { + enable = true; + feeds = [ + # Example feed - replace with your actual subscriptions + "https://www.youtube.com/feeds/videos.xml?channel_id=UCovVc-qqwYp8oqwO3Sdzx7w" + ]; + maxVideosPerFeed = 1; # Start with just 3 videos per feed for testing + }; }; programs.zsh.shellAliases = { diff --git a/modules/yt-dlp.nix b/modules/yt-dlp.nix index 57f8f97..853a421 100644 --- a/modules/yt-dlp.nix +++ b/modules/yt-dlp.nix @@ -23,6 +23,33 @@ in example = "/mnt/storage/videos"; description = "Base directory for downloaded videos"; }; + + subscriptions = { + enable = mkEnableOption "RSS subscription checking for automatic video downloads"; + + feeds = mkOption { + type = types.listOf types.str; + default = []; + example = [ + "https://www.youtube.com/feeds/videos.xml?channel_id=UCRHXUZ0BxbkU2MYZgsuFgkQ" + ]; + description = "List of YouTube RSS feed URLs to monitor for new videos"; + }; + + interval = mkOption { + type = types.str; + default = "hourly"; + example = "*-*-* *:30:00"; + description = "Systemd timer schedule for checking subscriptions"; + }; + + maxVideosPerFeed = mkOption { + type = types.int; + default = 5; + example = 10; + description = "Maximum number of videos to process per feed (newest first)"; + }; + }; }; config = mkIf cfg.enable { @@ -30,6 +57,8 @@ in home.packages = with pkgs; [ cfg.package ffmpeg + ] ++ lib.optionals cfg.subscriptions.enable [ + libxml2 # For xmllint to parse RSS feeds ]; # Cookie files - managed by Nix (read-only) @@ -84,6 +113,9 @@ in # Help dl-help = "download-help"; + } // lib.optionalAttrs cfg.subscriptions.enable { + # YouTube subscription management + dl-subs-yt = "check-youtube-subscriptions"; }; programs.zsh.initContent = '' @@ -330,6 +362,52 @@ in # Alias for backward compatibility alias dlv-clear-archive='dl-clear-archive' + + # YouTube RSS subscription checker + check-youtube-subscriptions() { + ${lib.optionalString cfg.subscriptions.enable '' + local max_videos="${toString cfg.subscriptions.maxVideosPerFeed}" + local feeds=(${lib.concatMapStringsSep " " (feed: ''"${feed}"'') cfg.subscriptions.feeds}) + + if [[ ''${#feeds[@]} -eq 0 ]]; then + echo "No RSS feeds configured" + return 0 + fi + + echo "Checking ''${#feeds[@]} YouTube subscription feeds..." + echo "Processing up to $max_videos videos per feed" + echo "" + + for feed in "''${feeds[@]}"; do + echo "Processing feed: $feed" + + # Fetch and parse the RSS feed, extract video links + local links=$(${pkgs.curl}/bin/curl -s "$feed" | \ + ${pkgs.libxml2}/bin/xmllint --xpath "//*[local-name()='entry']/*[local-name()='link'][@rel='alternate']/@href" - 2>/dev/null | \ + sed 's/href="//g; s/"//g' | \ + head -n "$max_videos") + + if [[ -z "$links" ]]; then + echo " No videos found or feed unavailable" + continue + fi + + local count=0 + while IFS= read -r link; do + if [[ -n "$link" ]]; then + ((count++)) + echo " [$count] Downloading: $link" + download-youtube "$link" + fi + done <<< "$links" + + echo " Processed $count videos from this feed" + echo "" + done + + echo "✓ Subscription check completed" + ''} + } ''; }; }