Add subscription functionality to yt-dlp module

This commit is contained in:
Yan Lin 2025-09-21 21:40:47 +02:00
parent a610990056
commit ed4fd5293f
2 changed files with 86 additions and 0 deletions

View file

@ -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 = {

View file

@ -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"
''}
}
'';
};
}