What is the pytube module in Python?

pytube is a lightweight Python library for downloading YouTube videos.

This shot will discuss the use of the pytube python library to download YouTube videos.

Installation

pip install pipenv 
pipenv shell
pipenv install pytube

Code

Create a file and name it app.py.

from pytube import YouTube
import os
from pathlib import Path
def interface():
# python terminal input
url = input('url: ')
yt = YouTube(url)
#the directory to store the downloads
downloads_path = str(Path.home() / "Downloads")
# download the video and store it in a folder called "YoutubeVideos" inside the downloads folder
yt.streams.get_highest_resolution().download(output_path=os.path.join(downloads_path, 'YoutubeVideos'))
# calling the function
interface()

Go to your terminal, navigate to the directory where you have created the file and, then type:

python app.py

It will prompt you for the url of the YouTube Video. Paste the link and click enter to download the specific video.

Free Resources