There is a treasure trove of useful Python tips and tricks available online. Here are some fun/cool tricks that you can use to beef up your Python game and impress your friends at the same time. Two birds in one stone.

Without further ado, let’s jump right into it.

1) Download YouTube videos with youtube-dl

You can easily download YouTube videos (and many other websites) using the **youtube-dl **module in Python.

Let’s first install the module using pip.

pip install youtube-dl

Once installed, you can download videos directly from Terminal or Command Prompt by using the following one-line command:

youtube-dl <Your video link here>

Alternatively, since youtube-dl has bindings for Python, you can create a Python script to do the same programmatically.

You can create a list with all the links and download the videos using the quick-and-dirty script below.

Sample code to create a list with all the links and download the videos using the youtube-dl module

With this module, you can not only download videos, but you can also download entire playlists, metadata, thumbnails, subtitles, annotations, descriptions, audio, and much more quite easily.

The easiest way to achieve this is by adding a bunch of these parameters to a dictionary and pass it on to the YoutubeDL object constructor.

In the example code below, I created a dictionary, ydl_options, with a bunch of parameters, and passed it on to the constructor.

Sample code to use youtube-dl with a number of parameters passed as options

1\. 'format':'bestvideo+bestaudio' #Dowloads the video in the best available video and audio format.

2\. 'writethumbnail':'writethumbnail' #Downloads the thumbnail image of the video.
3\. 'writesubtitles':'writesubtitles' #Downloads the subtitles, if any.
4\. 'writedescription':'writedescription' #Writes the video description to a .description file.

Note:_ You can do everything directly within Terminal or Command Prompt, but using a Python script is better due to the flexibility/reusability it offers._

You can find more details about the module here: Github:youtube-dl

#data-science #python #computer-science #technology #programming

7 Cool Python Tricks That You (Probably) Didn’t Know
10.50 GEEK