-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
94 lines (72 loc) · 2.62 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import os
PACKAGES = ["customtkinter", "requests", "pytube"]
for package in PACKAGES:
os.system(f"pip install {package}")
import customtkinter as ctk
import tkinter as tk
import requests
from pytube import YouTube
video_directory = "./Videos"
thumbnail_directory = "./Thumbnails"
if not os.path.exists(video_directory):
os.makedirs(video_directory)
if not os.path.exists(thumbnail_directory):
os.makedirs(thumbnail_directory)
def download_youtube_video():
url = link_input.get()
if url:
try:
yt = YouTube(url)
title = yt.title
yt.streams.filter(progressive=True, file_extension='mp4')
yt.streams.get_highest_resolution().download(output_path=video_directory)
log_message.set("Successfully downloaded: " + str(title))
print("Successfully downloaded: " + str(title))
except Exception as e:
log_message.set(f"An error occurred: {e}")
def download_youtube_thumbnail():
url = link_input.get()
if url:
try:
yt = YouTube(url)
title = yt.title
img_url = yt.thumbnail_url
content = requests.get(img_url).content
minia = open(thumbnail_directory + "/" + title.replace(" ", "") + ".png", "wb")
minia.write(content)
minia.close()
log_message.set("Successfully downloaded: " + str(title) + ".png")
print("Successfully downloaded: " + str(title) + ".png")
except Exception as e:
log_message.set(f"An error occurred: {e}")
root = ctk.CTk()
root.title("YouTool")
root.geometry("600x400")
root.wm_iconbitmap("assets/icon.ico")
icon = tk.PhotoImage(file="assets/logo.png")
icon = icon.subsample(4, 4)
logo = ctk.CTkLabel(root, image=icon, text="")
logo.pack(pady=5)
label = ctk.CTkLabel(root, text="YouTool", font=("Arial", 20))
label.pack()
#Download Video Method
label = ctk.CTkLabel(root, text="Download Video", font=("Arial", 12))
label.pack()
link_input = ctk.CTkEntry(root)
link_input.pack()
download_button = ctk.CTkButton(root, text="Download", command=download_youtube_video)
download_button.pack(pady=2)
#Download Thumbnail
label = ctk.CTkLabel(root, text="Download Thumbnail", font=("Arial", 12))
label.pack()
link_input = ctk.CTkEntry(root)
link_input.pack()
download_button = ctk.CTkButton(root, text="Download", command=download_youtube_thumbnail)
download_button.pack(pady=2)
#Extre
log_message = ctk.StringVar()
error_label = ctk.CTkLabel(root, textvariable=log_message)
error_label.pack(pady=5)
download_button = ctk.CTkButton(root, text="@GaelHF")
download_button.pack(pady=5)
root.mainloop()