first commit

This commit is contained in:
Pulguer Gonzalo 2022-08-02 15:38:13 -03:00
commit e25625fa35
3 changed files with 143 additions and 0 deletions

33
downloader.py Normal file
View File

@ -0,0 +1,33 @@
from pytube import YouTube
import os
path = os.path.abspath(os.getcwd())
def DownloadMP3(url, destination):
yt = YouTube(url)
newpath = path + "/Downloads/Audio"
if len(destination)==0:
check = os.path.exists(newpath)
if not check:
os.makedirs(newpath)
destination = newpath
vid = yt.streams.filter(only_audio=True).first()
out_file = vid.download(output_path=destination)
n = os.path.splitext(out_file)
filename = n[0] + '.mp3'
os.rename(out_file, filename)
def DownloadMP4(url, quality, destination):
yt = YouTube(url)
newpath = path + "/Downloads/Video"
if len(destination)==0:
check = os.path.exists(newpath)
if not check:
os.makedirs(newpath)
destination = newpath
if quality == "MaxQ":
vid = yt.streams.get_highest_resolution()
else:
vid = yt.streams.filter(res=quality).first()
out_file = vid.download(output_path=destination)

110
gui.py Normal file
View File

@ -0,0 +1,110 @@
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from tkinter import messagebox
import os.path
import downloader
check = os.path.exists("dir.txt")
if check == False:
f = open("dir.txt", "w")
f.close()
qlist = [
"144p",
"240p",
"360p",
"480p",
"MaxQ"
]
mp = [
"Audio (MP3)",
"Video (MP4)"
]
# Root
root = Tk()
root.title("GonTube")
root.geometry("390x400")
root.resizable(False, False)
icon = Image("photo", file="icon.png")
root.tk.call('wm', 'iconphoto', root._w, icon)
# Settings
def openSettings():
nw = Toplevel(root)
nw.title("Settings")
nw.geometry("350x150")
nw.tk.call('wm', 'iconphoto', nw._w, icon)
nw.resizable(False, False)
Label(nw, text="Directory").grid(column=1, row=2, padx=20, pady=50)
def Save():
root.filename = filedialog.askdirectory(initialdir = "/",title = "Select directory")
f = open("dir.txt", "w")
f.write(root.filename)
f.close()
dirb = Button(nw, text="Change Directory", command=Save).grid(column=2, row=2, padx=50, sticky=E)
# Menu
menu_bar = Menu(root)
menu = Menu(menu_bar, tearoff=0)
menu_bar.add_cascade(label="Options", menu=menu)
menu.add_command(label="Settings", command=openSettings)
menu.add_command(label="Info")
root.config(menu=menu_bar)
# Link field
link = StringVar()
link_entry = ttk.Entry(root, width=25, textvariable=link)
link_entry.grid(column=2, row=3, padx=20, pady=80)
# Labels
Label(root, text="Quality", font=(None, 23)).grid(column=1, row=2, pady=40, sticky = W)
Label(root, text="Format", font=(None, 23)).grid(column=1, row=1, pady=40, sticky = W)
Label(root, text="URL", font=(None, 23)).grid(column=1, row=3, pady=40, sticky = W)
# Buttons and Stuff
var1 = StringVar()
var1.set(qlist[4])
var2 = StringVar()
var2.set(mp[0])
qdd = OptionMenu(root, var1, *qlist)
qdd.grid(column=2, row=2, pady=20, padx=5, sticky = E)
mdd = OptionMenu(root, var2, *mp)
mdd.grid(column=2, row=1, pady=20, padx=5, sticky = E)
# Popups :)
def popup():
messagebox.showinfo("GonTube", "Done")
def Download():
quality = var1.get()
mpf = var2.get()
url = link.get()
f = open("dir.txt", "r")
dire = f.readline()
f.close()
if(mpf == "Audio (MP3)"):
downloader.DownloadMP3(url, dire)
else:
downloader.DownloadMP4(url, quality, dire)
link_entry.delete(0, 'end')
popup()
downb = Button(root, text="Download", command=Download).grid(column=3, row=3)
root.mainloop()

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB