-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
48 lines (29 loc) · 1.25 KB
/
main.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
from pytube import *
# Importing tkinter module
from tkinter import *
# creating root window for Tkinter
root = Tk()
# adding root window title and dimension for Tkinter
root.title("Python Youtube Video Downloader")
root.geometry('350x200')
# Passing the url in the pytube function, that is YouTube
yt = YouTube(video_url)
# adding a label to the root window
lbl = Label(root, text = "Please enter a valid Youtube URL: ")
lbl.grid()
# adding Entry Field
video_url = Entry(root, width=10)
video_url.grid(column =1, row =0)
# function to convert the Youtube URL into a .mp4 file in the current directory when button is clicked
def clicked():
# Passing the url in the pytube function, that is YouTube
yt = pytube.YouTube(video_url.get())
# Here you have to choose any one format of the stream (format contains mime_type, resolution, fps, vcodec, acodec). Also, you can change it if you want but I've chosen the first format.
video = yt.streams.first()
# Downloads the .mp4 file into the current directory. You can change it if you want.
video.download()
# button widget with text inside
btn = Button(root, text = "Start Converting" ,
fg = "black", command=clicked)
btn.grid(column=2, row=0)
root.mainloop()