Download Youtube video with just 5 lines of Python code

Tram Ho

1. Introduction

Surely all of us have tried to find ways to download videos on Youtube for many different reasons.

Today I would like to introduce a simple method to download Youtube video using Python or Command Line that I have read.

※ Although the library stated in the article does not infringe copyrights, we also need to be responsible for the videos downloaded from Youtube.

2. Install 「youtube_dl」 library

First of all, we need to install the youtube_dl library

3. Download Youtube video with Python

To download a Youtube video, we just need to create and run a python file with the following content.

To download the desired video, just replace the URL https://www.youtube.com/watch?v=~ in line 5 with the URL of the corresponding video.

※ If you keep the following code, you can download a short video of VTV24 channel

4. Download Youtube video by Command Line

In addition, after install, we can also download it by the command line. Only with the command as below

Options

Network Options

Where can not download video

  • Chances are there has been a change on the youtube side, so you cannot download the video
  • Such times need to wait for the update from the youtube_dl library
  • After the update is available, you can use the following command to update to the latest version.

5. Conclusion

youtube_dl is an interesting library for beginners to the Python language.

From using this library one can continue with other newer programming ideas (creating a tool that automatically collects Youtube videos for example)

Have a good time programming, as well as watching YouTube videos!

References

【Python】 youtube の 動画 を コ ピ ペ 5 行 で ダ ウ ンン ロ ド す 方法 (性 な し)

Share the news now

Source : Viblo