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.
pip install pipenv
pipenv shell
pipenv install pytube
Create a file and name it app.py
.
from pytube import YouTubeimport osfrom pathlib import Pathdef interface():# python terminal inputurl = input('url: ')yt = YouTube(url)#the directory to store the downloadsdownloads_path = str(Path.home() / "Downloads")# download the video and store it in a folder called "YoutubeVideos" inside the downloads folderyt.streams.get_highest_resolution().download(output_path=os.path.join(downloads_path, 'YoutubeVideos'))# calling the functioninterface()
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.