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.
If you haven’t checked out my previous article on the same topic but not the GUI version, please check it out.
Have you guys ever wanted to download your entire youtube playlist?rahulbhatt1899.medium.com
So before starting to code let's check if you have all the requirements beforehand:
Pre-requirements:
- Qt designer
- Anaconda or mini conda or python 3.7 compiler
- Any text editor of your choice
Libraries to download:
- Pytube
- Ffmpy
- PyQt5
This would be sectioned into the following structure:
- Creating the UI in Qt designer
- Converting UI file into Python file
- 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.

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.

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.

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

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

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

Add click event handling to submit and browse buttons.

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

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

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.
- radioButton — mp4
- radioButton_2 — mp3
- radioButton_3 — video
- radioButton_4 — playlist

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.

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

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.

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

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

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

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

Now you will be able to download YouTube videos or entire playlists in mp3 or mp4 format.
Thank you for your attention.
Please do check out the references without which this article wasn’t possible:
References:
Learn about this official set of Python bindings for Qt that enable the use of Qt APIs in Python applications. Explore…www.qt.io
Comments
Post a Comment