Downloading Video from YouTube using Python

YouTube is a rich source of videos and downloading videos from YouTube is a little difficult. There are some extensions and downloaders available but those are sometimes not recommended. But in Python, it is quite easy to download video from YouTube.

So, in this blog we will learn how to download videos from YouTube directly using video link.

  • To download videos from YouTube, we will use a python library named ‘pytube’. First you need to install ‘pytube’ using following command.
  • Now we are having all necessary libraries required for this task. Now import the required module from ‘pytube’ library.
  • The only thing that you will need from video is it’s video link.
  • Then create an object of the earlier imported module ‘YouTube’ using this video link.
  • After getting object we need to get stream and from that get the first result of the stream which will be our required video.
  • Now we have our video stream, to download it just call the following function.

The above code will download the video in the current working directory with the name of the video as it was in the YouTube. To download it to a specific folder with specific name you need pass two arguments in the above code as below.

That was a simple code to download videos from YouTube. Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.

1 thought on “Downloading Video from YouTube using Python

Leave a Reply