Close this search box.

Download YouTube video with Python

Table of Contents

1. Introduction

Sometimes you like video on YouTube so much that you want to keep it on your computer. This is good because every video can disappear if author wants and if YouTube will delete his account (see article about it). In this tutorial I will guide you how to do it using Python language.

2. Package installation

2.1. Install anaconda

To make it simple I used anaconda package manager. Below commands to install required dependencies. Check your environment and modify URL to point to your system.

					curl -O

2.2. Install pytube

					conda install pytube

3. Run script and get video

					cat<<EOF >
from pytube import YouTube
import argparse

parser = argparse.ArgumentParser(description="Downloading movie from YouTube")
parser.add_argument("--videourl", type=str, help="Provide URL from YouTube", default="")

args = parser.parse_args()
url = args.videourl

yt = YouTube(url)
yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first().download()

You can run script without any arguments so it will download sample video

					conda run python

or specify URL to get your favorite one

					conda run python --videourl ""

4. Summary

In this tutorial you have learned how to create python script and use it to download video from YouTube.

Have a nice coding!

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow me on LinkedIn
Share the Post:

Enjoy Free Useful Amazing Content

Related Posts