Whenever I need to download video/audio from Youtube, I just google search "download video from youtube", and randomly pick one result from the first page. Until today, I come across a 'thing', called yt-dlp. It can easily let me download any thing from Youtube, fast.
1. What is yt-dlp:
- I don't know exactly, but it can let me directly: Downloads videos, audio, subtitles, or metadata from websites like YouTube.
- Why Use It?: Faster and more reliable than web-based downloaders, with precise control (e.g., audio-only, specific formats). It’s command-line but easy to learn for my Mac.
- Learn more at: https://github.com/yt-dlp/yt-dlp
2. Prerequisites for Mac
Before using yt-dlp, ensure these are installed:
- Homebrew (package manager):
- If already installed, update:
brew update
FFmpeg
(for audio extraction and format conversion):
- Verify:
ffmpeg -version
- Python 3.9+ :
- Check:
python3 --version
- If not, ensure Python 3.11 is installed via Homebrew:
brew install python@3.11- Installing yt-dlp on Your Mac:
- Install yt-dlp:
pip3 install yt-dlp
V
erify:
3. Core yt-dlp Functions
1. Download Audio Only
- Command:
yt-dlp -x --audio-format mp3 "YOUTUBE_URL" -o "~/whisper_project/%(title)s.%(ext)s"
- -x: Extracts audio only.
- --audio-format mp3: Converts to MP3 (requires FFmpeg).
- -o "~/whisper_project/%(title)s.%(ext)s": Saves to ~/whisper_project with the video’s title (e.g., MKBHD Review.mp3).
- Replace YOUTUBE_URL with the video link (e.g., https://www.youtube.com/watch?v=VIDEO_ID).
- Example:
yt-dlp -x --audio-format mp3 "https://www.youtube.com/watch?v=rjRV0G6qWgw" -o audio.mp3
- Downloads audio as audio.mp3 in current directory.
- Tip: Use --audio-quality 0 for the best quality (e.g., ~256kbps MP3 equivalent to YouTube’s 160kbps Opus).
yt-dlp -x --audio-format mp3 --audio-quality 0 "YOUTUBE_URL" -o "~/whisper_project/%(title)s.%(ext)s"
2. Download Video (For Screenshots or Full Content)
- Command:
yt-dlp -f "bv*[height<=1080]+ba" "YOUTUBE_URL" -o "~/whisper_project/%(title)s.%(ext)s"
- -f "bv*[height<=1080]+ba": Downloads the best video up to 1080p with the best audio.
- Saves as MP4 (e.g., MKBHD.mp4).
- Example:
yt-dlp -f "bv*[height<=1080]+ba" "https://www.youtube.com/watch?v=rjRV0G6qWgw" -o "~/whisper_project/MKBHD.mp4"
- Tip: Use -F to see available formats first:
yt-dlp -F "YOUTUBE_URL"
- Lists formats (e.g., 137: 1080p, 140: audio). Pick one with -f if needed.
3. Download Subtitles (If Available).
- Command:
yt-dlp --write-auto-sub --sub-format srt --skip-download "YOUTUBE_URL" -o "~/whisper_project/%(title)s"
- --write-auto-sub: Downloads auto-generated subtitles (if available).
- --sub-format srt: Saves as SRT (compatible with Whisper’s output).
- --skip-download: Skips video/audio, only gets subtitles.
- Saves as Video Title.en.srt (English subtitles).
- Example:
yt-dlp --write-auto-sub --sub-format srt --skip-download "https://www.youtube.com/watch?v=rjRV0G6qWgw" -o Title.srt
- Tip: Check subtitle availability:
yt-dlp --list-subs "YOUTUBE_URL"
- If none, use Whisper to generate them.
4. Download Playlists (For Batch Processing)
- Command:
yt-dlp -x --audio-format mp3 --yes-playlist "PLAYLIST_URL" -o "~/whisper_project/%(playlist_index)s_%(title)s.%(ext)s"
- --yes-playlist: Downloads all videos in the playlist.
- -o: Names files with index (e.g., 1_MKBHD Review.mp3, 2_Tech Review.mp3).
- Example:
yt-dlp -x --audio-format mp3 --yes-playlist "https://www.youtube.com/playlist?list=PLu4wnki9NI_8VmJ7Qz_byhKwCquXcy6u9" -o "~/whisper_project/%(playlist_index)s_%(title)s.%(ext)s"
- Downloads all playlist audio files.
- Tip: Limit playlist items:
yt-dlp -x --audio-format mp3 --playlist-items 1,3-5 "PLAYLIST_URL" -o "~/whisper_project/%(playlist_index)s_%(title)s.%(ext)s"
- Downloads only videos 1, 3, 4, and 5.
5. Download Specific Video Sections (For Short Clips)
- Why: If you only need a segment (e.g., a 2-minute Switch 2 demo for subtitles), save time and bandwidth.
- Command:
yt-dlp --download-sections "*10:00-12:00" -x --audio-format mp3 "YOUTUBE_URL" -o "~/whisper_project/%(title)s_clip.%(ext)s"
- --download-sections "*10:00-12:00": Downloads from 10:00 to 12:00.
- Saves as Video Title_clip.mp3.
- Example:yt-dlp --download-sections "*10:00-12:00" -x --audio-format mp3 "https://www.youtube.com/watch?v=rjRV0G6qWgw" -o "~/whisper_project/%(title)s_clip.%(ext)s"
- Gets a 2-minute audio clip for Whisper.
- Tip: Requires FFmpeg. Use for fair use quotes (e.g., short article excerpts).
Comments
Post a Comment