Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

What is the pytube module in Python?

Njoku Ifeanyi Gerald

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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()
app.py

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.

RELATED TAGS

python
communitycreator

CONTRIBUTOR

Njoku Ifeanyi Gerald

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring