A lightweight terminal-based YouTube download tool with optional flags to open the file explorer after downloading, play the video, and more.
- Download YouTube videos directly from the terminal.
- Specify output file name as a second argument.
- Download to the system's Downloads folder with the
-dflag. - Open the file explorer after downloading with the
-oflag. - Play the video immediately after downloading with the
-pflag. - Choose video quality (
bestorworst) with the-qflag. - Specify video format (e.g.,
mp4,mp3) with the-fflag.
- Python 3.x
- yt-dlp package
- ffmpeg (if you wish to convert files)
-
Clone or download this repository.
-
Install Dependencies:
pip install -r requirements.txt Alternatively, install yt-dlp directly: pip install yt-dlp```
python youtube_downloader.py [options] <YouTube_URL> [output_file_name]
Or make the script executable (Unix/Linux):
chmod +x youtube_downloader.py
./youtube_downloader.py [options] <YouTube_URL> [output_file_name]
-d,--downloads: Download to the system's Downloads folder.-o,--open: Open the file explorer after downloading.-p,--play: Play the video immediately after downloading.-q,--quality: Choose the video quality to download (bestorworst). Defaults tobest.-f,--format: Specify the video format (e.g.,mp4,webm,mp3).-h,--help: Show help message and exit.--list-formats: List all available formats for the given URL, then exit.--subtitles: Download subtitles for the video.--sub-lang: Comma-separated subtitle languages (default: en) to use when downloading subtitles.--cookies: Path to a cookies file (e.g., cookies.txt).--max-downloads: Maximum number of videos to download (useful for playlists).
-
Download a video with default file name and format:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -
Download a video with a specified output file name:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" myvideo.mp4 -
Download to the Downloads folder with a specified file name:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" myvideo.mp4 -d -
Attempt to download to a subdirectory in Downloads (will raise an error):
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" folder/subfolder/myvideo.mp4 -dError: Cannot combine a custom output path with the '-d' flag.Remove the path from the output file name or do not use the '-d' flag. -
Download a video to a specific directory specified in the output file name:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" folder/subfolder/myvideo.mp4 -
Download a video with a specified format, warning if extension doesn't match:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" myvideo.webm -f mp4Warning: The file extension of 'myvideo.webm' does not match the specified format 'mp4'. Proceeding anyway. -
Download and play the video after downloading:
python youtube_downloader.py "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -p -
List all available formats for a URL (no download):
python youtube_downloader.py --list-formats "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -
Download subtitles (default: English) along with the video:
python youtube_downloader.py --subtitles "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -
Download subtitles in multiple languages:
python youtube_downloader.py --subtitles --sub-lang "en,es" "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -
Use a cookies file:
python youtube_downloader.py --cookies /path/to/cookies.txt "https://www.youtube.com/watch?v=dQw4w9WgXcQ" -
Limit total downloads to 1 (useful for playlists):
python youtube_downloader.py --max-downloads 1 "https://www.youtube.com/watch?v=PLAYLIST_LINK"
- Downloads Folder Detection: The script automatically detects the Downloads folder across Windows, macOS, and Linux.
- Output File Name and Paths:
- If the
-dflag is used to download to the Downloads folder, and the output file name includes a path (e.g.,folder/subfolder/myvideo.mp4), the script raises an error. - If only a file name is provided (without a path), it is saved in the Downloads folder when
-dis used. - If a custom path is included in the output file name, do not use the
-dflag.
- If the
- File Extension Checks:
- The script warns if the file extension of the output file name doesn't match the specified or default format but proceeds with the download.
- Dependencies: Install the yt-dlp package using pip install yt-dlp.
- Respect YouTube's Terms of Service: Be mindful of YouTube's policies regarding content downloading.