In this article i want to show you How to Download YouTube Videos in Python, as you know YouTube is the most powerful and popular video sharing platform in the world. and in article this we want to learn downloading YouTube videos in python. for downloading youtube videos we want to use pytube3 library, pytube is a very lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.
Installation
First of all you need to install this library, you can use pip for the installation.
1 |
pip install pytube3 |
So first we want to print the title and the thumbnail url for the video. in this code first
we have imported our library and after that you need to create the object of the YouTube
and you need to add the video url that you want to print the title and thumbnail, at the
end we print the title and also the thumbnail url.
1 2 3 4 5 6 7 |
from pytube import YouTube yt = YouTube('https://youtu.be/F8UZ4EClJAQ') print(yt.title) print(yt.thumbnail_url) |
So you will receive this result.

You can get video views and video id.
1 2 3 4 5 6 |
from pytube import YouTube yt = YouTube('https://youtu.be/F8UZ4EClJAQ') print(yt.video_id) print(yt.views) |
This is the result.

Also you can find the the video author and video description.

Also you can find the available video formats using this code.
1 2 3 4 5 6 |
from pytube import YouTube yt = YouTube('https://youtu.be/F8UZ4EClJAQ') stream = yt.streams.first() print(stream) |
And you can Download YouTube Videos in Python using this code, in here we want to download the first resolution or the lowest resolution of the video.
1 2 3 4 5 6 7 |
from pytube import YouTube yt = YouTube('https://youtu.be/F8UZ4EClJAQ') stream = yt.streams.first() print(stream) stream.download() |
For downloading YouTube Playlist you can use this code.
1 2 3 4 |
from pytube import Playlist pl = Playlist("add playlist url in here") pl.download_all |
By using this code you can download the highest resolution video.
1 2 3 4 |
from pytube import YouTube yt = YouTube('https://youtu.be/F8UZ4EClJAQ') yt.streams.get_highest_resolution().download() |
Join Our Free Courses