-
Notifications
You must be signed in to change notification settings - Fork 0
/
YouTube_Downloader.py
104 lines (82 loc) · 3.04 KB
/
YouTube_Downloader.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
95
96
97
98
99
100
101
102
103
104
import tkinter
import tkinter.filedialog
from tkinter import messagebox
import webbrowser
from pytube import YouTube
from urllib.request import urlopen
from PIL import Image, ImageTk
from io import BytesIO
import os
w = tkinter.Tk()
radio = tkinter.IntVar()
w.title("Youtube Downloader")
w.geometry("800x500")
# Select path to download
def browse():
global path
path = tkinter.filedialog.askdirectory()
l3 = tkinter.Label(w,text=path,height = 2,width =50)
l3.grid(row=1,column=1)
thumbnail()
details()
# Display youtube video thumbnail
def thumbnail():
url = urltextbox.get("1.0","end-1c")
yt = YouTube(url)
tn = yt.thumbnail_url
rawtn= urlopen(tn).read()
img = Image.open(BytesIO(rawtn)).resize((240,180))
tkimg = ImageTk.PhotoImage(img)
l5.configure(image=tkimg)
l5.image= tkimg
def details():
url = urltextbox.get("1.0","end-1c")
yt = YouTube(url)
l4 = tkinter.Label(w,text= yt.title,height = 2,width =80)
l4.grid(row=5,column=1,columnspan=3)
def res():
global resolution
resolution = str(radio.get())
def git():
webbrowser.open_new("https://github.com/aadityaaatreya/Youtube-Downloader")
def lkdn():
webbrowser.open_new("www.linkedin.com/in/aaditya-aatreya")
# Initiate download
def download():
url = urltextbox.get("1.0","end-1c")
try:
yt = YouTube(url)
except:
messagebox.showinfo("info", "Video unavailable")
else:
yt.streams.get_by_itag(resolution).download(path)
messagebox.showinfo("info", "Downloaded")
l1 = tkinter.Label(w,text="Video URL")
l1.grid(row=0,column=0)
urltextbox = tkinter.Text(w,height = 2, width = 50)
urltextbox.grid(row=0,column=1)
l2 = tkinter.Label(w,text="Path")
l2.grid(row=1,column=0)
browse_button = tkinter.Button(w,text="Browse",command=browse,font=("Arial Italic",15), bg="green",fg ="white")
browse_button.grid(row=1,column=2)
l3 = tkinter.Label(w,text="Resolution")
l3.grid(row=2,column=0)
radio_button1 = tkinter.Radiobutton(w,text = "360p",variable= radio,value=18, command = res )
radio_button1.grid(row=2,column=1)
radio_button2 = tkinter.Radiobutton(w,text = "720p",variable= radio,value=22, command = res )
radio_button2.grid(row=3,column=1)
radio_button3 = tkinter.Radiobutton(w,text = "Audio",variable= radio,value=251, command = res )
radio_button3.grid(row=4,column=1)
download_button = tkinter.Button(w,text="Download",command=download, font=("Arial Italic",15), bg="red",fg ="white")
download_button.grid(row=3,column=2)
github_button = tkinter.Button(w,text="GitHub",command=git, font=("sans serif",20), bg="black",fg ="white")
github_button.grid(row=6,column=1)
linkedin_button = tkinter.Button(w,text="LinkedIn",command=lkdn, font=("Myriad Pro",20), bg="#0077b5",fg ="white")
linkedin_button.grid(row=6,column=2)
# Default thumbnail view
cwd = os.getcwd()
deftn=cwd+"\\res\\youtube-logo.png" # Default thumbnail image path
ytlogo = ImageTk.PhotoImage(file=deftn)
l5 = tkinter.Label(w, image = ytlogo)
l5.grid(row=5,column=0)
w.mainloop()