Create Program to Download Video from Youtube


In this tutorial, you will learn to create program to download video from YouTube. You need to install and import pytube in order to continue this tutorial. The source code to install and import pytube and datetime is detailed below.

#!pip install pytube
#pip3 install pytube
import pytube
from datetime import datetime as time
def download_video(url, save_loc, resolution="1080p"):
  yt = pytube.YouTube(url)
  video = yt.streams.filter(resolution=resolution).first()
  # Additional info from the video you download
  file_size = (int(video.filesize)/1000)/1000 # Convert from bytes to kb then to mb
  print(f"Downloading video: {video.title}, Filesize: {file_size} MB")
  start_time =
  finish_time =
  print(f"Finished downloading, download time: {finish_time-start_time} seconds")

video_url = ""
video_folder = "./"
video_resolution = "720p"
download_video(video_url, video_folder, video_resolution)
Downloading video: Sword Art Online: Alicization - War of Underworld Opening Full『Haruka Tomatsu - Resolution』, Filesize: 9.169068 MB
Finished downloading, download time: 0:02:09.138037 seconds
Back To Top