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 ...

First Repeating Element | Easy | Techgig

First Repeating Element | Easy | Techgig C++ Solution First Repeating Element | Easy | Techgig C++ Solution The first repeating element is the problem that comes under the Linear Search problem under the Algorithm section. Linear Search or sequential search is a method for finding an element within a list. The algorithm works by selecting and checking each number sequentially until matched. A linear search runs in at the worst linear time and makes at most n comparisons, where n is the length of the list. If each element is equally likely to be searched, then the sequential search has an average case of (n+1)/2 comparisons, but the average case can be affected if the search probabilities for each element vary. The complexity of the linear search is as follows: The basic linear search algorithm has the following steps: Given a list L on n elements with values L0…Ln-1, and target value T, to find the index of the target T in the list L. Set i to 0. If Li = T , the search te...

Data Scraping with Python 2020

Are you a regular coursera user? If yes, then you might like this python program. You can actually use the same program for similar course websites like edx, alison, udemy, etc. So, let’s start. If you have some experience with python and BeautifulSoup then you already have everything you need so make your own. The ones that don’t, follow along. Install python for your operating system. After that install requests and BeautifulSoup like this: After that, lets import the modules, and make a variable to store the url: from bs4 import BeautifulSoup import requests baseUrl = “https://www.coursera.org” Now, take an input from cli or initialize it: skillset = input().split(“ “)  Now, we’ll see the query url for the search input: example: java Fig.1. Search field in a course website Fig.2. Check the url and find a pattern So, the important part is the after the “query=” part. So, we will append the input from the user here. skillset= “%20”.join(input().split(“ “)) courseraUrl = “https://...