fix: fix video downloader skill
This commit is contained in:
@@ -1,106 +1,99 @@
|
|||||||
---
|
---
|
||||||
name: video-downloader
|
name: youtube-downloader
|
||||||
description: Downloads videos from YouTube and other platforms for offline viewing, editing, or archival. Handles various formats and quality options.
|
description: Download YouTube videos with customizable quality and format options. Use this skill when the user asks to download, save, or grab YouTube videos. Supports various quality settings (best, 1080p, 720p, 480p, 360p), multiple formats (mp4, webm, mkv), and audio-only downloads as MP3.
|
||||||
---
|
---
|
||||||
|
|
||||||
# Video Downloader
|
# YouTube Video Downloader
|
||||||
|
|
||||||
This skill downloads videos from YouTube and other platforms directly to your computer.
|
Download YouTube videos with full control over quality and format settings.
|
||||||
|
|
||||||
## When to Use This Skill
|
## Quick Start
|
||||||
|
|
||||||
- Downloading YouTube videos for offline viewing
|
The simplest way to download a video:
|
||||||
- Saving educational content for reference
|
|
||||||
- Archiving important videos
|
|
||||||
- Getting video files for editing or repurposing
|
|
||||||
- Downloading your own content from platforms
|
|
||||||
- Saving conference talks or webinars
|
|
||||||
|
|
||||||
## What This Skill Does
|
```bash
|
||||||
|
python scripts/download_video.py "https://www.youtube.com/watch?v=VIDEO_ID"
|
||||||
1. **Downloads Videos**: Fetches videos from YouTube and other platforms
|
|
||||||
2. **Quality Selection**: Lets you choose resolution (480p, 720p, 1080p, 4K)
|
|
||||||
3. **Format Options**: Downloads in various formats (MP4, WebM, audio-only)
|
|
||||||
4. **Batch Downloads**: Can download multiple videos or playlists
|
|
||||||
5. **Metadata Preservation**: Saves title, description, and thumbnail
|
|
||||||
|
|
||||||
## How to Use
|
|
||||||
|
|
||||||
### Basic Download
|
|
||||||
|
|
||||||
```
|
|
||||||
Download this YouTube video: https://youtube.com/watch?v=...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
This downloads the video in best available quality as MP4 to `/mnt/user-data/outputs/`.
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
### Quality Settings
|
||||||
|
|
||||||
|
Use `-q` or `--quality` to specify video quality:
|
||||||
|
|
||||||
|
- `best` (default): Highest quality available
|
||||||
|
- `1080p`: Full HD
|
||||||
|
- `720p`: HD
|
||||||
|
- `480p`: Standard definition
|
||||||
|
- `360p`: Lower quality
|
||||||
|
- `worst`: Lowest quality available
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```bash
|
||||||
|
python scripts/download_video.py "URL" -q 720p
|
||||||
```
|
```
|
||||||
Download this video in 1080p quality
|
|
||||||
|
### Format Options
|
||||||
|
|
||||||
|
Use `-f` or `--format` to specify output format (video downloads only):
|
||||||
|
|
||||||
|
- `mp4` (default): Most compatible
|
||||||
|
- `webm`: Modern format
|
||||||
|
- `mkv`: Matroska container
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```bash
|
||||||
|
python scripts/download_video.py "URL" -f webm
|
||||||
```
|
```
|
||||||
|
|
||||||
### Audio Only
|
### Audio Only
|
||||||
|
|
||||||
```
|
Use `-a` or `--audio-only` to download only audio as MP3:
|
||||||
Download the audio from this YouTube video as MP3
|
|
||||||
|
```bash
|
||||||
|
python scripts/download_video.py "URL" -a
|
||||||
```
|
```
|
||||||
|
|
||||||
### Playlist Download
|
### Custom Output Directory
|
||||||
|
|
||||||
```
|
Use `-o` or `--output` to specify a different output directory:
|
||||||
Download all videos from this YouTube playlist: [URL]
|
|
||||||
|
```bash
|
||||||
|
python scripts/download_video.py "URL" -o /path/to/directory
|
||||||
```
|
```
|
||||||
|
|
||||||
### Batch Download
|
## Complete Examples
|
||||||
|
|
||||||
```
|
1. Download video in 1080p as MP4:
|
||||||
Download these 5 YouTube videos:
|
```bash
|
||||||
1. [URL]
|
python scripts/download_video.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -q 1080p
|
||||||
2. [URL]
|
|
||||||
...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Example
|
2. Download audio only as MP3:
|
||||||
|
```bash
|
||||||
**User**: "Download this YouTube video: https://youtube.com/watch?v=abc123"
|
python scripts/download_video.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -a
|
||||||
|
|
||||||
**Output**:
|
|
||||||
```
|
|
||||||
Downloading from YouTube...
|
|
||||||
|
|
||||||
Video: "How to Build Products Users Love"
|
|
||||||
Channel: Lenny's Podcast
|
|
||||||
Duration: 45:32
|
|
||||||
Quality: 1080p
|
|
||||||
|
|
||||||
Progress: ████████████████████ 100%
|
|
||||||
|
|
||||||
✓ Downloaded: how-to-build-products-users-love.mp4
|
|
||||||
✓ Saved thumbnail: how-to-build-products-users-love.jpg
|
|
||||||
✓ Size: 342 MB
|
|
||||||
|
|
||||||
Saved to: ~/Downloads/
|
|
||||||
```
|
```
|
||||||
|
|
||||||
**Inspired by:** Lenny's workflow from his newsletter
|
3. Download in 720p as WebM to custom directory:
|
||||||
|
```bash
|
||||||
|
python scripts/download_video.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -q 720p -f webm -o /custom/path
|
||||||
|
```
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
The skill uses `yt-dlp`, a robust YouTube downloader that:
|
||||||
|
- Automatically installs itself if not present
|
||||||
|
- Fetches video information before downloading
|
||||||
|
- Selects the best available streams matching your criteria
|
||||||
|
- Merges video and audio streams when needed
|
||||||
|
- Supports a wide range of YouTube video formats
|
||||||
|
|
||||||
## Important Notes
|
## Important Notes
|
||||||
|
|
||||||
⚠️ **Copyright & Fair Use**
|
- Downloads are saved to `/mnt/user-data/outputs/` by default
|
||||||
- Only download videos you have permission to download
|
- Video filename is automatically generated from the video title
|
||||||
- Respect copyright laws and platform terms of service
|
- The script handles installation of yt-dlp automatically
|
||||||
- Use for personal, educational, or fair use purposes
|
- Only single videos are downloaded (playlists are skipped by default)
|
||||||
- Don't redistribute copyrighted content
|
- Higher quality videos may take longer to download and use more disk space
|
||||||
|
|
||||||
## Tips
|
|
||||||
|
|
||||||
- Specify quality if you need lower file size (720p vs 1080p)
|
|
||||||
- Use audio-only for podcasts or music to save space
|
|
||||||
- Download to a dedicated folder to stay organized
|
|
||||||
- Check file size before downloading on slow connections
|
|
||||||
|
|
||||||
## Common Use Cases
|
|
||||||
|
|
||||||
- **Education**: Save tutorials and courses for offline learning
|
|
||||||
- **Research**: Archive videos for reference
|
|
||||||
- **Content Creation**: Download your own content from platforms
|
|
||||||
- **Backup**: Save important videos before they're removed
|
|
||||||
- **Offline Viewing**: Watch videos without internet access
|
|
||||||
|
|
||||||
145
video-downloader/scripts/download_video.py
Normal file
145
video-downloader/scripts/download_video.py
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
YouTube Video Downloader
|
||||||
|
Downloads videos from YouTube with customizable quality and format options.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def check_yt_dlp():
|
||||||
|
"""Check if yt-dlp is installed, install if not."""
|
||||||
|
try:
|
||||||
|
subprocess.run(["yt-dlp", "--version"], capture_output=True, check=True)
|
||||||
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||||
|
print("yt-dlp not found. Installing...")
|
||||||
|
subprocess.run([sys.executable, "-m", "pip", "install", "--break-system-packages", "yt-dlp"], check=True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_video_info(url):
|
||||||
|
"""Get information about the video without downloading."""
|
||||||
|
result = subprocess.run(
|
||||||
|
["yt-dlp", "--dump-json", "--no-playlist", url],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
return json.loads(result.stdout)
|
||||||
|
|
||||||
|
|
||||||
|
def download_video(url, output_path="/mnt/user-data/outputs", quality="best", format_type="mp4", audio_only=False):
|
||||||
|
"""
|
||||||
|
Download a YouTube video.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
url: YouTube video URL
|
||||||
|
output_path: Directory to save the video
|
||||||
|
quality: Quality setting (best, 1080p, 720p, 480p, 360p, worst)
|
||||||
|
format_type: Output format (mp4, webm, mkv, etc.)
|
||||||
|
audio_only: Download only audio (mp3)
|
||||||
|
"""
|
||||||
|
check_yt_dlp()
|
||||||
|
|
||||||
|
# Build command
|
||||||
|
cmd = ["yt-dlp"]
|
||||||
|
|
||||||
|
if audio_only:
|
||||||
|
cmd.extend([
|
||||||
|
"-x", # Extract audio
|
||||||
|
"--audio-format", "mp3",
|
||||||
|
"--audio-quality", "0", # Best quality
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
# Video quality settings
|
||||||
|
if quality == "best":
|
||||||
|
format_string = "bestvideo+bestaudio/best"
|
||||||
|
elif quality == "worst":
|
||||||
|
format_string = "worstvideo+worstaudio/worst"
|
||||||
|
else:
|
||||||
|
# Specific resolution (e.g., 1080p, 720p)
|
||||||
|
height = quality.replace("p", "")
|
||||||
|
format_string = f"bestvideo[height<={height}]+bestaudio/best[height<={height}]"
|
||||||
|
|
||||||
|
cmd.extend([
|
||||||
|
"-f", format_string,
|
||||||
|
"--merge-output-format", format_type,
|
||||||
|
])
|
||||||
|
|
||||||
|
# Output template
|
||||||
|
cmd.extend([
|
||||||
|
"-o", f"{output_path}/%(title)s.%(ext)s",
|
||||||
|
"--no-playlist", # Don't download playlists by default
|
||||||
|
])
|
||||||
|
|
||||||
|
cmd.append(url)
|
||||||
|
|
||||||
|
print(f"Downloading from: {url}")
|
||||||
|
print(f"Quality: {quality}")
|
||||||
|
print(f"Format: {'mp3 (audio only)' if audio_only else format_type}")
|
||||||
|
print(f"Output: {output_path}\n")
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Get video info first
|
||||||
|
info = get_video_info(url)
|
||||||
|
print(f"Title: {info.get('title', 'Unknown')}")
|
||||||
|
print(f"Duration: {info.get('duration', 0) // 60}:{info.get('duration', 0) % 60:02d}")
|
||||||
|
print(f"Uploader: {info.get('uploader', 'Unknown')}\n")
|
||||||
|
|
||||||
|
# Download the video
|
||||||
|
subprocess.run(cmd, check=True)
|
||||||
|
print(f"\n✅ Download complete!")
|
||||||
|
return True
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"\n❌ Error downloading video: {e}")
|
||||||
|
return False
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n❌ Error: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Download YouTube videos with customizable quality and format"
|
||||||
|
)
|
||||||
|
parser.add_argument("url", help="YouTube video URL")
|
||||||
|
parser.add_argument(
|
||||||
|
"-o", "--output",
|
||||||
|
default="/mnt/user-data/outputs",
|
||||||
|
help="Output directory (default: /mnt/user-data/outputs)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-q", "--quality",
|
||||||
|
default="best",
|
||||||
|
choices=["best", "1080p", "720p", "480p", "360p", "worst"],
|
||||||
|
help="Video quality (default: best)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-f", "--format",
|
||||||
|
default="mp4",
|
||||||
|
choices=["mp4", "webm", "mkv"],
|
||||||
|
help="Video format (default: mp4)"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-a", "--audio-only",
|
||||||
|
action="store_true",
|
||||||
|
help="Download only audio as MP3"
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
success = download_video(
|
||||||
|
url=args.url,
|
||||||
|
output_path=args.output,
|
||||||
|
quality=args.quality,
|
||||||
|
format_type=args.format,
|
||||||
|
audio_only=args.audio_only
|
||||||
|
)
|
||||||
|
|
||||||
|
sys.exit(0 if success else 1)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user