Skip to main content

Create your own YouTube video and playlist downloader using QT designer in Python

Create your own YouTube video and playlist downloader using QT designer in Python

The code for this software is available on my GitHub, the link is given below.

Create your own YouTube video and playlist downloader using QT designer in Python

This is the thing we are trying to make today for this article

The code for this software is available on my GitHub, the link is given below.

If you haven’t checked out my previous article on the same topic but not the GUI version, please check it out.

So before starting to code let's check if you have all the requirements beforehand:

Pre-requirements:

  1. Qt designer
  2. Anaconda or mini conda or python 3.7 compiler
  3. Any text editor of your choice

Libraries to download:

  1. Pytube
  2. Ffmpy
  3. PyQt5

This would be sectioned into the following structure:

  1. Creating the UI in Qt designer
  2. Converting UI file into Python file
  3. Creating relevant functions

Creating the UI in Qt designer

After opening Qt designer you can create a similar structure or something else or you can just download the code from my Github repo.

Qt designer layout we will be used for designing the app

The below section depicts the mapping between class and its instance, so if you cannot follow the code comeback to this image and it will be clear or you obviously can check out the entire code in my Github repo.

Total elements in the YouTube video downloader

Converting UI file into Python file

After creating the UI for your software, you’ll use this command to convert the UI file into a py file.

pyuic5 -x filename.ui -o filename.py

Now, you can check out the py file and understand how the Qt designer has automatically created the code for PyQt5 with two methods inside Ui_Main class.

The overall structure of the software

Ui_Main class is the main class where the UI is defined and setupUi() and retranslateUi() methods that define the structure in PyQt5.

after creating a py file with the command

These are the variable names that I am using, this information will be useful for you to understand the code.

These will be the variable names that we will be using in the app

Again the radioButton variable name mapping with UI just so that you can understand what the code is trying to do.

radio buttons names that I have given

Add click event handling to submit and browse buttons.

Adding the event handler for the two buttons

The browse() button function is simple, it is used to set the download directory of your mp4 or mp3 files.

Browse button function

The Show_pop() function is used to display “Download is complete”.

Showing a completion message after successful download

The submit button function is where the magic happens. The following is the structure of the submit function. It is taking the input from the textbox and displaying it on the list view.

The conditional statements are used to check whether radio buttons are clicked or not.

The following is a mapping of radio button variables to the functionality they will be providing if checked.

  1. radioButton — mp4
  2. radioButton_2 — mp3
  3. radioButton_3 — video
  4. radioButton_4 — playlist
Submit button function structure

This is code for downloading the YouTube video or playlist in mp4 format.

The nested conditional statements are for checking if video or playlist radio buttons are checked or not.

If mp4 is checked

These two radio buttons are to separate whether we are downloading a video or an entire playlist.

Code for if the video or playlist or none is checked

This code is used to download the YouTube video or playlist in mp3 format. Pytube doesn’t allow in mp3 format but you can download the file in mp4 and convert it into mp3 using ffmpy.

If mp3 is checked

This code is used to download YouTube videos in mp3 format in your chosen download directory.

If mp3 is checked and if the video is checked

This code is used to download the YouTube playlist in mp3 format in your chosen download directory.

If mp3 is checked and if the playlist is checked

The nested else condition is just to check if the video or playlist radio buttons are checked or not.

If none of the radio buttons among video or playlist is checked

The outer else condition is just to check if the mp3 or mp4 radio buttons are checked or not.

If none of the mp3 or mp4 radio buttons is checked

Now you will be able to download YouTube videos or entire playlists in mp3 or mp4 format.

Thank you for your attention.



Comments

Popular posts from this blog

How to use Chess com API using Python

  How to use Chess com API using Python Chess is an amazing strategy-based game and if you have been following the recent boom of online chess then welcome to the chess club. Online chess is amazing since it allows you to play with a random stranger at your level or stockfish (computer). There are many popular online chess websites like lichess.org, chess.com, playchess.com, and newly created kasparovchess.com. Today we will be seeing how to use chess.com API for getting players' stats. You can create software and get affiliates from them (check out the link below), so share it with them if you are planning to create something. Before you start make sure you have the following things: Pre-requirements Postman Anaconda or mini conda or Python idle Any text editor of your choice Pretty good? Now let’s download the JSON file that chess com developers have already made for us from here and then you import it to the Postman. This just helps you with prewritten get methods so that ...

Authentication Using Passport JS

Authentication is big and most complicated part of an application, but it is also the  preponderance  part of any web app/software in general. Passport JS Passport JS is a widely popular authentication module for  Node js.  The sole purpose is to authenticate requests and is based on the idea of pluggable authentication strategies ( including local strategy, there are more than 500 strategies currently  available  ). When using third party application Your app never receives your password  thus freeing the developer from the burden of security related to handling and storing passwords. The Passport authentication and its strategy will include protection against attacks like “man in the middle” and other vectors an attacker might exploit. We are going to use Facebook strategy, for now, to install Passport and Facebook strategy type in the following command: Next, we are going to write the authentication code, and we’ll be creating a different module cal...