Skip to content

Commit b086be4

Browse files
authored
Merge pull request #801 from mgndolan/main
Python3 GUI for youtube-dl
2 parents 6279212 + e696737 commit b086be4

File tree

6 files changed

+146
-0
lines changed

6 files changed

+146
-0
lines changed

youtube_dl_gui/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Youtube Downloader Python3 GUI
2+
3+
This application displays a pop-up GUI for the Youtube Downloader tool using Tkinter. Tkinter is a Python module used to create cross-platform GUIs. This application can download YouTube videos in different resolutions, with captions (if available). For more information about the Youtube Downloader tool itself, see the README.md file in the youtube_downloader folder.
4+
5+
## Setup
6+
7+
For Unix based systems please execute the following command to create venv and install requirements :
8+
9+
```bash
10+
make init
11+
source .venv/bin/activate
12+
```
13+
14+
Install all of the necessary dependencies, such as:
15+
```
16+
pip install pytube
17+
```
18+
19+
## How it works:
20+
1. Run the script `YoutubeDL.py` by typing either:
21+
```bash
22+
python3 YoutubeDL.py
23+
```
24+
or
25+
```bash
26+
python YoutubeDL.py
27+
```
28+
2. A window will pop up that looks like the following screen:
29+
30+
![Mac display of Youtube Downloader application](./images/YTDL.png)
31+
32+
Enter in the URL of a YouTube video, as well as the local path to wherever you would like
33+
the video saved to. The directory path is an optional field, although it will download the
34+
video to the current directory if no other path is specified.
35+
36+
3. Click on the "Download Video" button. The video may take awhile to download. The button will
37+
update status to display "Downloading... Please Wait" while `ytdownloader.py` is executing (see image
38+
below). Once the video is finished downloading, the button text will return to normal.
39+
40+
![Mac display of Youtube Downloader - downloading video](./images/YTDL_download.png)
41+
42+
43+
4. To download another video, type in another URL and repeat the process.
44+
45+
## Author(s)
46+
47+
Megan Dolan @mgndolan
48+
(GUI for work done on youtube_downloader)

youtube_dl_gui/YoutubeDL.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import os
2+
from time import sleep
3+
import tkinter as tk
4+
from PIL import Image, ImageTk
5+
from threading import Thread
6+
7+
# initialize tkinter GUI
8+
root = tk.Tk()
9+
root.title("YouTube Downloader")
10+
11+
# Global variables to save YT Downloader parameters
12+
ytParams = ""
13+
14+
canvas = tk.Canvas(root, width=650, height=120)
15+
canvas.grid(columnspan=3, rowspan=5)
16+
17+
# YouTube Downloader - title
18+
label = tk.Label(root, text="YouTube Downloader")
19+
label.grid(columnspan=3, row=0, pady=30)
20+
label.configure(font=("Courier", 28, "bold"))
21+
22+
img = Image.open('images/youtube-logo.png')
23+
img = ImageTk.PhotoImage(img)
24+
img_label = tk.Label(image=img)
25+
img_label.image = img
26+
img_label.grid(columnspan=3, row=1)
27+
28+
descTxt = "Download your favorite YouTube videos by entering a URL below."
29+
# Brief tool explanation
30+
desc = tk.Label(root, text=descTxt)
31+
desc.grid(columnspan=3, row=2, pady=10)
32+
desc.configure(font=("Courier", 14))
33+
34+
# Prompts the user to enter a YouTube URL
35+
urlLabel = tk.Label(text="YouTube URL:")
36+
urlLabel.grid(column=0, row=3, pady=20)
37+
urlLabel.configure(font=("Courier", 16))
38+
39+
urlEntry = tk.Entry(root, width=45, borderwidth=2)
40+
urlEntry.grid(column=1, row=3, pady=20)
41+
42+
# Prompts the user to enter a download path if necessary
43+
pathLabel = tk.Label(text="Download Path:")
44+
pathLabel.grid(column=0, row=4, pady=20)
45+
pathLabel.configure(font=("Courier", 16))
46+
47+
pathEntry = tk.Entry(root, width=45, borderwidth=2)
48+
pathEntry.grid(column=1, row=4, pady=20)
49+
50+
downloadButton = tk.StringVar()
51+
downloadButton.set("Download Video")
52+
53+
54+
# Function to alert user that the video is downloading.
55+
class first(Thread):
56+
def run(self):
57+
downloadButton.set("Downloading... Please Wait")
58+
sleep(2)
59+
60+
61+
# Function to run youtube_downloader python script.
62+
class second(Thread):
63+
def run(self):
64+
command = "python ../youtube_downloader/ytdownloader.py "
65+
url = urlEntry.get()
66+
ytPath = ""
67+
68+
path = pathEntry.get()
69+
if path:
70+
ytPath = " -p " + path
71+
72+
if not ytPath:
73+
runPy = command + " " + url
74+
else:
75+
runPy = command + " " + url + ytPath
76+
os.system(runPy)
77+
78+
downloadButton.set("Download Video")
79+
80+
81+
# Call each function so the class values execute in order.
82+
def downloadVideo():
83+
first().start()
84+
second().start()
85+
86+
87+
getVideo = tk.Button(root, textvariable=downloadButton,
88+
fg="red", command=downloadVideo,
89+
font=("Courier", 15), height=2)
90+
getVideo.grid(columnspan=3, row=6, pady=10)
91+
92+
93+
root.mainloop()

youtube_dl_gui/images/YTDL.png

174 KB
Loading
202 KB
Loading
2.36 KB
Loading

youtube_dl_gui/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tkinter
2+
requests
3+
pkg-resources==0.0.0
4+
pytube3==9.6.4
5+
typing-extensions==3.7.4.3

0 commit comments

Comments
 (0)