-
Notifications
You must be signed in to change notification settings - Fork 0
/
youtool.py
83 lines (64 loc) · 2.31 KB
/
youtool.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
import tkinter as tk
import requests
from pytube import YouTube
import os
import crayons
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_video.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(crayons.green("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 + ".png", "wb")
minia.write(content)
minia.close()
log_message.set("Successfully downloaded: " + str(title) + ".png")
print(crayons.green("Successfully downloaded: " + str(title) + ".png"))
except Exception as e:
log_message.set(f"An error occurred: {e}")
root = tk.Tk()
root.title("YouTool")
root.geometry("600x400")
label = tk.Label(root, text="YouTool", font=("Arial", 20))
label.pack()
#Download Video Method
label = tk.Label(root, text="Download Video", font=("Arial", 12))
label.pack()
link_input_video = tk.Entry(root)
link_input_video.pack()
download_button = tk.Button(root, text="Download", command=download_youtube_video)
download_button.pack(pady=2)
#Download Thumbnail
label = tk.Label(root, text="Download Thumbnail", font=("Arial", 12))
label.pack()
link_input = tk.Entry(root)
link_input.pack()
download_button = tk.Button(root, text="Download", command=download_youtube_thumbnail)
download_button.pack(pady=2)
#Extre
log_message = tk.StringVar()
error_label = tk.Label(root, textvariable=log_message)
error_label.pack(pady=5)
download_button = tk.Button(root, text="@GaelHF")
download_button.pack(pady=5)
root.mainloop()