import youtube_dl
import time
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import font as tkFont
#application to download youtube song's with or without video
#pretty slow but took a lot of work
#application looks like it's freezing during the downloading process. this is normal.
#name tk function "window" and give it a cool title.
window = Tk()
window.title("SUPER AWESOME YOUTUBE DOWNLOADER V1")
#create window size, xy method
window.geometry('575x400')
#setup useless progress bar (makes sense later)
progress = Progressbar(window, orient=HORIZONTAL,
length=250, mode='determinate')
#make background red
window.configure(bg='red')
def A_option():
#download song
#retrieve input
vid = entry1.get()
#to only get audio you need specific inputs in ytlib library. no idea why this works, but i got it from the web.
#used a try statement because program can be buggy sometimes. this way it will work nonetheless.
#outtmpl is for the download's destination, not sure if this means the code has to change on other computers...
try:
ytlib = {
'format': 'bestaudio/best',
'noplaylist': True,
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s',
'continue_dl': True,
'postprocessors_args': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
'preferredquality': 'max'}]
}
except Exception:
print('something went wrong...')
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def bar():
#progress bar
#couldn't manage to make it show the actual downloading process...
#looks pretty neat so i'm keeping it
progress['value'] = 20
window.update_idletasks()
time.sleep(1)
progress['value'] = 40
window.update_idletasks()
time.sleep(1)
progress['value'] = 50
window.update_idletasks()
time.sleep(1)
progress['value'] = 60
window.update_idletasks()
time.sleep(1)
progress['value'] = 80
window.update_idletasks()
time.sleep(1)
progress['value'] = 100
window.mainloop()
def B_option():
#download video
#only had to put outtmpl here because it downloads video's automatically
vid = entry1.get()
ytlib = {
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s'
}
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def delete():
#clears input window (didn't go automatic because i suck)
entry1.delete(0, 'end')
def stop():
#imidiatly terminates process
print('Program finished')
quit()
def setup():
#here comes the sloppy part
#font size
foptions = tkFont.Font(family='Helvetica', size=15, weight=tkFont.NORMAL)
#create a collum
#determine distance inbetween rows of buttons and stuff
window.columnconfigure(index=0, weight=0)
window.rowconfigure(index=0, weight=0)
#create label to point to input box
#row is how far down the item is, column is how far right.
elink = Label(window, text='Enter youtube link below:', font=foptions, bg='red')
elink.grid(row=0, column=0, columnspan=2)
#get youtube link input here
#make the entry field global, because that makes sense?
global entry1
entry1 = Entry(window, width=50, font=foptions, bg='red', fg='black')
entry1.grid(row=1, column=0, columnspan=2)
#empty progress bar. does not really do anything usefull but looks cool and took a lot of effort.
#tried to apply it to the actual progress, but i'm not that good....
#idk what "pady" does, but internet said to do so and it works.
the_lie = Label(window, text='Completing download:', font=foptions, bg='red')
the_lie.grid(row=4, column=0, columnspan=2)
progress.grid(row=5, column=0, columnspan=2, pady=10)
#buttons to the options of the app with some modifications to look slightly less bad.
Button(window, text='download song', font=foptions, width=15, height=5, bg='black', fg='red', command=A_option).grid(row=2, column=0)
Button(window, text='download video', font=foptions, width=15, height=5, bg='black', fg='red', command=B_option).grid(row=2, column=1)
Button(window, text='clear entry', font=foptions, width=15, height=5, bg='black', fg='red', command=delete).grid(row=3, column=0)
Button(window, text='exit', font=foptions, width=15, height=5, bg='black', fg='red', command=stop).grid(row=3, column=1)
#always use them mainloops
window.mainloop()
setup()
```
import youtube_dl
import time
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import font as tkFont
#application to download youtube song's with or without video
#pretty slow but took a lot of work
#application looks like it's freezing during the downloading process. this is normal.
#name tk function "window" and give it a cool title.
window = Tk()
window.title("SUPER AWESOME YOUTUBE DOWNLOADER V1")
#create window size, xy method
window.geometry('575x400')
#setup useless progress bar (makes sense later)
progress = Progressbar(window, orient=HORIZONTAL,
length=250, mode='determinate')
#make background red
window.configure(bg='red')
def A_option():
#download song
#retrieve input
vid = entry1.get()
#to only get audio you need specific inputs in ytlib library. no idea why this works, but i got it from the web.
#used a try statement because program can be buggy sometimes. this way it will work nonetheless.
#outtmpl is for the download's destination, not sure if this means the code has to change on other computers...
try:
ytlib = {
'format': 'bestaudio/best',
'noplaylist': True,
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s',
'continue_dl': True,
'postprocessors_args': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
'preferredquality': 'max'}]
}
except Exception:
print('something went wrong...')
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def bar():
#progress bar
#couldn't manage to make it show the actual downloading process...
#looks pretty neat so i'm keeping it
progress['value'] = 20
window.update_idletasks()
time.sleep(1)
progress['value'] = 40
window.update_idletasks()
time.sleep(1)
progress['value'] = 50
window.update_idletasks()
time.sleep(1)
progress['value'] = 60
window.update_idletasks()
time.sleep(1)
progress['value'] = 80
window.update_idletasks()
time.sleep(1)
progress['value'] = 100
window.mainloop()
def B_option():
#download video
#only had to put outtmpl here because it downloads video's automatically
vid = entry1.get()
ytlib = {
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s'
}
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def delete():
#clears input window (didn't go automatic because i suck)
entry1.delete(0, 'end')
def stop():
#imidiatly terminates process
print('Program finished')
quit()
def setup():
#here comes the sloppy part
#font size
foptions = tkFont.Font(family='Helvetica', size=15, weight=tkFont.NORMAL)
#create a collum
#determine distance inbetween rows of buttons and stuff
window.columnconfigure(index=0, weight=0)
window.rowconfigure(index=0, weight=0)
#create label to point to input box
#row is how far down the item is, column is how far right.
elink = Label(window, text='Enter youtube link below:', font=foptions, bg='red')
elink.grid(row=0, column=0, columnspan=2)
#get youtube link input here
#make the entry field global, because that makes sense?
global entry1
entry1 = Entry(window, width=50, font=foptions, bg='red', fg='black')
entry1.grid(row=1, column=0, columnspan=2)
#empty progress bar. does not really do anything usefull but looks cool and took a lot of effort.
#tried to apply it to the actual progress, but i'm not that good....
#idk what "pady" does, but internet said to do so and it works.
the_lie = Label(window, text='Completing download:', font=foptions, bg='red')
the_lie.grid(row=4, column=0, columnspan=2)
progress.grid(row=5, column=0, columnspan=2, pady=10)
#buttons to the options of the app with some modifications to look slightly less bad.
Button(window, text='download song', font=foptions, width=15, height=5, bg='black', fg='red', command=A_option).grid(row=2, column=0)
Button(window, text='download video', font=foptions, width=15, height=5, bg='black', fg='red', command=B_option).grid(row=2, column=1)
Button(window, text='clear entry', font=foptions, width=15, height=5, bg='black', fg='red', command=delete).grid(row=3, column=0)
Button(window, text='exit', font=foptions, width=15, height=5, bg='black', fg='red', command=stop).grid(row=3, column=1)
#always use them mainloops
window.mainloop()
setup()
```
import youtube_dl
import time
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import font as tkFont
#application to download youtube song's with or without video
#pretty slow but took a lot of work
#application looks like it's freezing during the downloading process. this is normal.
#name tk function "window" and give it a cool title.
window = Tk()
window.title("SUPER AWESOME YOUTUBE DOWNLOADER V1")
#create window size, xy method
window.geometry('575x400')
#setup useless progress bar (makes sense later)
progress = Progressbar(window, orient=HORIZONTAL,
length=250, mode='determinate')
#make background red
window.configure(bg='red')
def A_option():
#download song
#retrieve input
vid = entry1.get()
#to only get audio you need specific inputs in ytlib library. no idea why this works, but i got it from the web.
#used a try statement because program can be buggy sometimes. this way it will work nonetheless.
#outtmpl is for the download's destination, not sure if this means the code has to change on other computers...
try:
ytlib = {
'format': 'bestaudio/best',
'noplaylist': True,
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s',
'continue_dl': True,
'postprocessors_args': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
'preferredquality': 'max'}]
}
except Exception:
print('something went wrong...')
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def bar():
#progress bar
#couldn't manage to make it show the actual downloading process...
#looks pretty neat so i'm keeping it
progress['value'] = 20
window.update_idletasks()
time.sleep(1)
progress['value'] = 40
window.update_idletasks()
time.sleep(1)
progress['value'] = 50
window.update_idletasks()
time.sleep(1)
progress['value'] = 60
window.update_idletasks()
time.sleep(1)
progress['value'] = 80
window.update_idletasks()
time.sleep(1)
progress['value'] = 100
window.mainloop()
def B_option():
#download video
#only had to put outtmpl here because it downloads video's automatically
vid = entry1.get()
ytlib = {
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s'
}
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def delete():
#clears input window (didn't go automatic because i suck)
entry1.delete(0, 'end')
def stop():
#imidiatly terminates process
print('Program finished')
quit()
def setup():
#here comes the sloppy part
#font size
foptions = tkFont.Font(family='Helvetica', size=15, weight=tkFont.NORMAL)
#create a collum
#determine distance inbetween rows of buttons and stuff
window.columnconfigure(index=0, weight=0)
window.rowconfigure(index=0, weight=0)
#create label to point to input box
#row is how far down the item is, column is how far right.
elink = Label(window, text='Enter youtube link below:', font=foptions, bg='red')
elink.grid(row=0, column=0, columnspan=2)
#get youtube link input here
#make the entry field global, because that makes sense?
global entry1
entry1 = Entry(window, width=50, font=foptions, bg='red', fg='black')
entry1.grid(row=1, column=0, columnspan=2)
#empty progress bar. does not really do anything usefull but looks cool and took a lot of effort.
#tried to apply it to the actual progress, but i'm not that good....
#idk what "pady" does, but internet said to do so and it works.
the_lie = Label(window, text='Completing download:', font=foptions, bg='red')
the_lie.grid(row=4, column=0, columnspan=2)
progress.grid(row=5, column=0, columnspan=2, pady=10)
#buttons to the options of the app with some modifications to look slightly less bad.
Button(window, text='download song', font=foptions, width=15, height=5, bg='black', fg='red', command=A_option).grid(row=2, column=0)
Button(window, text='download video', font=foptions, width=15, height=5, bg='black', fg='red', command=B_option).grid(row=2, column=1)
Button(window, text='clear entry', font=foptions, width=15, height=5, bg='black', fg='red', command=delete).grid(row=3, column=0)
Button(window, text='exit', font=foptions, width=15, height=5, bg='black', fg='red', command=stop).grid(row=3, column=1)
#always use them mainloops
window.mainloop()
setup()
youtube download application using youtube_dl and tkinter
I program in Python as a hobby and decided to try to use tkinter to make an application. I decided to make a YouTube video/audio downloader using youtube_dl. It's really slow, and the tkinter window freezes during the downloading process. But it still completes the download. Because this is the first time using tkinter, I'm not sure my program is very pythonic. Could I maybe get some pointers on how to improve? Thanks in advance!
import youtube_dl
import time
from tkinter import *
from tkinter.ttk import Progressbar
from tkinter import font as tkFont
#application to download youtube song's with or without video
#pretty slow but took a lot of work
#application looks like it's freezing during the downloading process. this is normal.
#name tk function "window" and give it a cool title.
window = Tk()
window.title("SUPER AWESOME YOUTUBE DOWNLOADER V1")
#create window size, xy method
window.geometry('575x400')
#setup useless progress bar (makes sense later)
progress = Progressbar(window, orient=HORIZONTAL,
length=250, mode='determinate')
#make background red
window.configure(bg='red')
def A_option():
#download song
#retrieve input
vid = entry1.get()
#to only get audio you need specific inputs in ytlib library. no idea why this works, but i got it from the web.
#used a try statement because program can be buggy sometimes. this way it will work nonetheless.
#outtmpl is for the download's destination, not sure if this means the code has to change on other computers...
try:
ytlib = {
'format': 'bestaudio/best',
'noplaylist': True,
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s',
'continue_dl': True,
'postprocessors_args': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
'preferredquality': 'max'}]
}
except Exception:
print('something went wrong...')
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def bar():
#progress bar
#couldn't manage to make it show the actual downloading process...
#looks pretty neat so i'm keeping it
progress['value'] = 20
window.update_idletasks()
time.sleep(1)
progress['value'] = 40
window.update_idletasks()
time.sleep(1)
progress['value'] = 50
window.update_idletasks()
time.sleep(1)
progress['value'] = 60
window.update_idletasks()
time.sleep(1)
progress['value'] = 80
window.update_idletasks()
time.sleep(1)
progress['value'] = 100
window.mainloop()
def B_option():
#download video
#only had to put outtmpl here because it downloads video's automatically
vid = entry1.get()
ytlib = {
'outtmpl': '/python_downloads/%(title)s-%(id)s.%(ext)s'
}
with youtube_dl.YoutubeDL(ytlib) as ydl:
ydl.download([vid])
print("download complete")
bar()
window.mainloop()
def delete():
#clears input window (didn't go automatic because i suck)
entry1.delete(0, 'end')
def stop():
#imidiatly terminates process
print('Program finished')
quit()
def setup():
#here comes the sloppy part
#font size
foptions = tkFont.Font(family='Helvetica', size=15, weight=tkFont.NORMAL)
#create a collum
#determine distance inbetween rows of buttons and stuff
window.columnconfigure(index=0, weight=0)
window.rowconfigure(index=0, weight=0)
#create label to point to input box
#row is how far down the item is, column is how far right.
elink = Label(window, text='Enter youtube link below:', font=foptions, bg='red')
elink.grid(row=0, column=0, columnspan=2)
#get youtube link input here
#make the entry field global, because that makes sense?
global entry1
entry1 = Entry(window, width=50, font=foptions, bg='red', fg='black')
entry1.grid(row=1, column=0, columnspan=2)
#empty progress bar. does not really do anything usefull but looks cool and took a lot of effort.
#tried to apply it to the actual progress, but i'm not that good....
#idk what "pady" does, but internet said to do so and it works.
the_lie = Label(window, text='Completing download:', font=foptions, bg='red')
the_lie.grid(row=4, column=0, columnspan=2)
progress.grid(row=5, column=0, columnspan=2, pady=10)
#buttons to the options of the app with some modifications to look slightly less bad.
Button(window, text='download song', font=foptions, width=15, height=5, bg='black', fg='red', command=A_option).grid(row=2, column=0)
Button(window, text='download video', font=foptions, width=15, height=5, bg='black', fg='red', command=B_option).grid(row=2, column=1)
Button(window, text='clear entry', font=foptions, width=15, height=5, bg='black', fg='red', command=delete).grid(row=3, column=0)
Button(window, text='exit', font=foptions, width=15, height=5, bg='black', fg='red', command=stop).grid(row=3, column=1)
#always use them mainloops
window.mainloop()
setup()
```
lang-py