But this time, changing the resolution to 360p: from pytube import YouTube Now let's put the entire code together in one place. Remember to replace video_path with your preferred download directory.
Video_streams.download(filename = "my first YouTube download2", Video_streams = (file_extension = 'mp4').get_by_itag(22) It also inherits the default title from YouTube.īut you can specify a download directory for your video and change the file name: video = YouTube(URL) The video, however, downloads to your current working directory in this case. Video_streams = (file_extension ='mp4').get_by_itag(22)
Now here's how to download a video at 720p resolution: video = YouTube(URL) Video_streams = (file_extension='mp4').get_by_itag(22) To check the title of a video: video = YouTube(URL) All you need is the itag value for your preferred resolution, which is always available when your print the streams for any video.
You can also increase the resolution to 1080p or any other available one if you want.
You can try the itag value for 360p to get a lower resolution. The resolution of the above stream is 720p ( res="720p"). You can call a stream using this itag value by including the get_by_itag() function: video_streams = (file_extension='mp4').get_by_itag(22) But when you look closely, each resolution has an itag value.įor instance, res="720" has itag="22", while the itag at 360p resolution is 18. The module, however, returns different stream resolutions, starting with 360p to 720p and 1080p (and maybe more). Replace file_name with the name of your Python file. You can run your Python code via the command line by calling your Python file like this: python file_name.py Once you instantiate a YouTube object with the URL of the video, you can print the streams available for it: video_streams = video.streams So pytube lets you download your video based on those. A video, however, has different stream resolutions. The pytube module works by giving you different stream options. Then create a YouTube instance on the next line of your Python file: URL = "Enter video URL" Go to YouTube and copy the URL of the video you wish to download.
Once you install pytube, go back into your text editor, open your Python file and import pytube: from pytube import YouTube To do that, enter the following command in your terminal: pip install pytube
To kick off this tutorial, you need to install a Python YouTube utility library called pytube using pip.
See Is It Legal to Download YouTube Videos? for more information.Ĭreate Your YouTube Downloader With Python Note: Only download videos when you have the proper authorization to do so. Related: Create a Virtual Environment in Python py file extension.Ĭreate a virtual environment and then open up any text editor you like to that location. Open up the command line to that directory and create a new Python file to the same location. If your terminal displays the Python version you downloaded earlier, then you've successfully installed Python on your PC. To test if Python is working on your PC after installation, open up your terminal and type: python -version Don't bother if you're using Mac, as it has Python pre-installed already.īut if you're on Windows, go to to download and install the latest version of Python on your PC. To get started, you need to get Python up and running on your PC. It's easy, and once you have everything set up, you may not need to reinvent the wheel for subsequent downloads. No worries if you're not familiar with Python programming, we'll provide you with what you need to get started. But you can make a reliable YouTube video downloader using Python. Downloading YouTube videos to your local storage is often an uphill battle, especially when dedicated YouTube downloaders keep failing you.