This Python script provides a tool for downloading videos from YouTube. It offers users the flexibility to choose the desired resolution for the downloaded video, including options for 360p, 720p, 1080p, 1440p, and 2160p.
This script utilises the PyTube and moviepy libraries to effortlessly download YouTube videos and audio files. It provides options to choose the desired download quality, including audio-only, 360p, 720p, 1080p, 1440p, and 2160p. For higher-resolution videos, it automatically merges the video and audio streams using moviepy to create a complete video file.
- Python 3.x
- PyTube library:
pip install pytube
- moviepy library:
pip install moviepy
- Download the
youtube_downloader.py
file to your local machine. - Open the terminal or command prompt and navigate to the directory containing the
youtube_downloader.py
file. - Run the script by entering the following command:
python youtube_downloader.py
- Enter the YouTube video URL when prompted.
- Choose the desired download quality from the available options:
audio
: Download only the audio track.360p
,720p
,1080p
,1440p
,2160p
: Download the video with the specified resolution.
- The downloaded file will be saved in the current working directory with the specified filename (default:
protocolten-<title>
). For audio-only downloads, the file extension will be.m4a
. For videos, the file extension will be.mp4
.
Download audio-only:
Enter the YouTube URL and select audio
as the download quality. The audio file will be saved with the filename protocolten-<title>.m4a
.
Download 1080p video:
Enter the YouTube URL and select 1080p
as the download quality. The complete video file will be saved with the filename protocolten-<title>.mp4
.
- The script performs basic checks to ensure the provided URL is valid and belongs to YouTube.
- The audio bitrate for
audio_only
and merging video/audio above 1080p is set to 128kbps. - The script handles downloading and merging video/audio files successively, ensuring that the video file is created only after the audio and video streams are successfully downloaded.