Share

How to download video from youtube using python module ?

Author: neptune | 22nd-May-2022 | views: 1091
#Python

We are going to learn how to download youtube videos using python module.

First of all you need to install the youtube-dl module. For installation follow the steps and commands.

Note: Windows user use pip instead of pip3.

~$ pip3 install youtube-dl
Collecting youtube-dl
Downloading youtube_dl-2020.6.16.1-py2.py3-none-any.whl (1.8 MB)
|████████████████████████████████| 1.8 MB 273 kB/s
Installing collected packages: youtube-dl
Successfully installed youtube-dl-2020.6.16.1





After installation you need a single command to download video, copy the link of video form the browser. As shown below paste the link in command prompt or terminal followed by youtube-dl.

~$ youtube-dl https://www.youtube.com/watch?v=jppi2eUAq2k
[youtube] jppi2eUAq2w: Downloading webpage
[download] Destination: Stay Home And Sing With Me-jppi2eUAq2w.mp4
[download] 0.4% of 758.49MiB at 241.61KiB/s ETA 53:20^Z

Downloading started.


You can also create a python script to download multiple videos at once.

For that create a python file (eg. download_video.py) and paste the below script or code into the file.

import youtube_dl

def download():
video_url = input("Enter URL: ")
video_info = youtube_dl.YoutubeDL().extract_info(
url=video_url, download = False
)
file = f"{video_info['title']}.mp3"
options={
'format':'bestvideo+bestaudio',
'writethumbnail':'writethumbnail',
'writesubtitles':'writesubtitles',
'writedescription':'writedescription'
}
with youtube_dl.YoutubeDL(options) as ydl:
ydl.download([video_info['webpage_url']])

if __name__ == '__main__':
download()





With the help of this you can also download entire playlists, metadata, thumbnails, subtitles, annotations, descriptions, audio, and many more more easily.

  1. 'format' : 'bestvideo+bestaudio' it will download the file in best quality.
  2. 'writethumbnail' : 'writethumbnail' download thumbnail image of video.
  3. 'writesubtitles' : 'writesubtitles' if subtitle is avilable then it will download.
  4. 'writedescription' : 'writedescription' write video description in a file.


I hope you successfully download the video if you face any problem plz let me know in the comment section.

Thanks for Reading!




anonymous | June 19, 2022, 7:47 a.m.

Helpful 👍


anonymous | Feb. 23, 2022, 1:59 p.m.

Awesome, I was able to download 😎



Related Blogs
How to extract Speech from Video using Python?
Author: neptune | 22nd-May-2022 | views: 1759
#Python
Simple and easy way to convert video into audio then text using Google Speech Recognition API...
Mostly asked Python Interview Questions - 2022.
Author: neptune | 25th-May-2022 | views: 702
#Python #Interview
Python interview questions for freshers. These questions asked in 2022 Python interviews...
Python 3.9 new amazing features ?
Author: neptune | 22nd-May-2022 | views: 682
#Python
We are going to explore the newest features of Python 3.9 really amazing features here list of some features like Dict union, Type hinting etc. with examples...
Python Built-in functions lambda, map, filter, reduce.
Author: neptune | 22nd-May-2022 | views: 586
#Python
We are going to explore in deep some important Python build-in functions lambda, map, filter and reduce with examples...
Best Python package manager and package for virtual environment ?
Author: neptune | 15th-Apr-2022 | views: 521
#Python #Anaconda #Virtualenv #Pip
Which is the best package manager for python and Virtual environment management using Virtualenv and Anaconda...
Will, AI kills Developer's jobs?
Author: neptune | 22nd-May-2022 | views: 432
#Python #Machine learning #AI
GPT-3’s performance has convinced that Artificial intelligence is closer or at least AI-generated code is closer than we think. It generates imaginative, insightful, deep, and even excellent content...
Do you know Jupyter is now full-fledged IDE?
Author: neptune | 15th-Apr-2022 | views: 350
#Python #Jupyter
Jupyter is a widely used tool by Data scientists. So developers from institutions like Two Sigma, Bloomberg and fast.ai convert it into IDE lets see..
What exactly you can do with Python?
Author: neptune | 15th-Apr-2022 | views: 317
#Python
Well, it's a tricky question to answer because there are lots of application of Python. But, I will tell you about 3 main applications of Python...
How to reverse string in Python ?
Author: neptune | 16th-May-2022 | views: 259
#Python
We are going to explore different ways to reverse string in Python...
Deploy Django project on AWS with Apache2 and mod_wsgi module.
Author: neptune | 22nd-May-2022 | views: 139
#Python #Django
In this blog I use the AWS Ubuntu 18.22 instance as Hosting platform and used Apache2 server with mod_wsgi for configurations. We create a django sample project then configure server...
Core Python Syllabus for Interviews
Author: neptune | 11th-Jun-2022 | views: 124
#Python #Interview
STRING MANIPULATION : Introduction to Python String, Accessing Individual Elements, String Operators, String Slices, String Functions and Methods...
Datatypes in Python.
Author: neptune | 22nd-May-2022 | views: 115
#Python
Python have different types of datatypes like Numbers, Strings, Lists, Tuples, Dictionary, Set, Frozenset, Bool, Mutable, and Immutable...
Introduction to Apache Spark
Author: neptune | 09th-May-2022 | views: 106
#Python #Apache Spark
Apache Spark is an open-source, distributed processing system that utilizes in-memory caching and optimized query execution for faster queries...
Input and Output in Python
Author: neptune | 15th-Jun-2022 | views: 50
#Python
In this article, we will see how Python take input from user and How it display the output to user. First we cover input then output...
View More