The YouTube Plugin is a built-in archiver plugin for Haven CLI that enables discovering and downloading videos from YouTube channels and playlists using yt-dlp.
- Channel & Playlist Support: Monitor multiple YouTube channels and playlists
- Quality Selection: Choose video quality from best, 1080p, 720p, 480p, or 360p
- Format Selection: Download in mp4, webm, or mkv formats
- Cookie Authentication: Support for YouTube cookies to download age-restricted content
- Duplicate Detection: Track seen videos to avoid downloading duplicates
- Retry Logic: Automatic retries for transient failures
- JavaScript Runtime Support: Automatic detection of Deno or Node.js for enhanced decryption
You must have yt-dlp installed on your system:
# macOS
brew install yt-dlp
# Linux (Ubuntu/Debian)
sudo apt install yt-dlp
# Or install via pip
pip install yt-dlp
# For latest version
pip install -U yt-dlpOptional: Install Deno or Node.js for enhanced YouTube signature decryption:
# Deno (recommended)
curl -fsSL https://deno.land/install.sh | sh
# Or Node.js
brew install node # macOS
sudo apt install nodejs # Ubuntu/DebianAdd YouTube plugin configuration to your Haven config file (~/.haven/config.toml):
[plugins.YouTubePlugin]
# YouTube channel IDs to monitor
channel_ids = ["UC_x5XG1OV2P6uZZ5FSM9Ttw", "UCanother_channel"]
# YouTube playlist IDs to monitor
playlist_ids = ["PLxxxxxxxxxxxxxx"]
# Maximum videos to discover per channel/playlist
max_videos = 20
# Video quality: best, 1080p, 720p, 480p, 360p
quality = "1080p"
# Container format: mp4, webm, mkv
format = "mp4"
# Output directory for downloads
output_dir = "~/haven/downloads/youtube"
# Path to YouTube cookies file (for age-restricted content)
cookies_file = "~/.config/haven/youtube_cookies.txt"
# Download subtitles
download_subtitles = false
# Maximum retry attempts
max_retries = 3To download age-restricted videos, you need to provide YouTube cookies:
-
Browser Extension Method (Recommended):
- Install "Get cookies.txt LOCALLY" extension (Chrome/Firefox)
- Sign in to YouTube in your browser
- Click the extension icon and export cookies
- Save to the path specified in
cookies_file
-
yt-dlp Method:
yt-dlp --cookies-from-browser chrome --cookies ~/haven/youtube_cookies.txt
from haven_cli.plugins import PluginManager
manager = PluginManager()
await manager.initialize_all()
# Or manually
from haven_cli.plugins.builtin import YouTubePlugin
plugin = YouTubePlugin(config={
"channel_ids": ["UC_x5XG1OV2P6uZZ5FSM9Ttw"],
"quality": "1080p",
"output_dir": "~/videos/youtube"
})
await plugin.initialize()# Discover new videos from configured channels/playlists
sources = await plugin.discover_sources()
for source in sources:
print(f"Found: {source.title}")
print(f"ID: {source.source_id}")
print(f"URI: {source.uri}")
print(f"Duration: {source.metadata.get('duration')} seconds")# Archive a discovered video
result = await plugin.archive(sources[0])
if result.success:
print(f"Downloaded to: {result.output_path}")
print(f"Size: {result.file_size} bytes")
print(f"Duration: {result.duration} seconds")
else:
print(f"Failed: {result.error}")# Check if plugin is healthy
is_healthy = await plugin.health_check()
print(f"Plugin healthy: {is_healthy}")import asyncio
from pathlib import Path
from haven_cli.plugins.builtin import YouTubePlugin
async def main():
# Configure plugin
plugin = YouTubePlugin(config={
"channel_ids": ["UCBa659QWEk1AI4Tg--mrJ2A"], # Tom Scott
"max_videos": 5,
"quality": "1080p",
"output_dir": "~/videos/youtube"
})
# Initialize
await plugin.initialize()
# Discover videos
sources = await plugin.discover_sources()
print(f"Discovered {len(sources)} new videos")
# Archive first video
if sources:
result = await plugin.archive(sources[0])
if result.success:
print(f"Downloaded: {result.output_path}")
else:
print(f"Failed: {result.error}")
# Cleanup
await plugin.shutdown()
if __name__ == "__main__":
asyncio.run(main())Make sure yt-dlp is installed and in your PATH:
which yt-dlp
yt-dlp --versionIf you see "No JavaScript runtime detected", some videos may fail to download. Install Deno or Node.js:
curl -fsSL https://deno.land/install.sh | shYouTube may rate-limit excessive requests. The plugin includes automatic retries with exponential backoff. If you continue to experience issues:
- Reduce
max_videossetting - Add delays between operations
- Use cookies from an authenticated session
If age-restricted videos still fail after setting cookies:
- Ensure cookies are in Netscape format
- Verify cookie file path is correct
- Re-export cookies (they expire)
- Ensure you're signed into YouTube when exporting
The main plugin class implementing ArchiverPlugin.
initialize(): Initialize the plugin and verify yt-dlpshutdown(): Save state and cleanuphealth_check(): Check if plugin is operationaldiscover_sources(): Discover new videos from channels/playlistsarchive(source): Download a videoconfigure(config): Update plugin configuration
Configuration dataclass for the plugin.
channel_ids: List of YouTube channel IDsplaylist_ids: List of YouTube playlist IDsmax_videos: Maximum videos to discover (default: 10)quality: Video quality (default: "best")format: Container format (default: "mp4")output_dir: Output directory (default: "./downloads")cookies_file: Path to cookies file (optional)download_subtitles: Download subtitles (default: False)max_retries: Max retry attempts (default: 3)