Tkinter YT Downloader dengan Resolusi
from tkinter import *
import pafy
class YouTubeDownloader:
def __init__(self,master):
self.master = master
master.title("Youtube Downloader")
self.media_option = StringVar()
self.audio_quality_lsit = []
self.audio_quality_drop_menu = StringVar()
self.video_quality_lsit = []
self.video_quality_drop_menu = StringVar()
Label(master, text="YouTube URL:").grid(row=0)
self.url_field = Entry(master)
self.url_field.grid(row=0, column=1)
Button(master, text='Paste URL', command=self.url).grid(row=0, column=4, sticky=W, pady=10)
Button(master, text='Download', command=self.download).grid(row=12, column=4, sticky=W, pady=10)
Label(master, text="Media Type: ").grid(row=3)
media_drop_menu = OptionMenu(master, self.media_option, "Audio", "Video", command=self.media_select)
media_drop_menu.grid(row=5, column=0)
def url(self):
global data
url = self.url_field.get()
data = pafy.new(url)
def media_select(self):
global A_V
A_V = self.media_option.get()
if A_V == "Audio":
audio()
elif A_V == "Video":
video()
def audio():
global selected_audio
audio_streams = self.data.audiostreams
for audio_quality in audio_streams:
audio_quality_lsit.append(audio_quality.bitrate)
selected_audio = audio_quality_drop_menu.get()
print("selected_audio") #Debug Statement
Label(master, text="Audio Bitrate: ").grid(row=7, column=1)
show_drop_menu = OptionMenu(master, audio_quality_drop_menu, *audio_quality_lsit)
show_drop_menu.grid(row=9, column=1)
def video(self):
global selected_video
video_streams = self.data.streams
for video_quality in video_streams:
video_quality_lsit.append(video_quality.resolution)
selected_video = video_quality_drop_menu.get()
print("selected_video") #Debug Statement
Label(master, text="Video Quality: ").grid(row=7, column=1)
show_drop_menu = OptionMenu(master, video_quality_drop_menu, *video_quality_lsit)
show_drop_menu.grid(row=9, column=1)
def download(self):
if selected_audio:
print("Audio") #Debug Statement
self.selected_audio.download(quiet=False)
elif selected_video:
print("Video") #Debug Statement
self.selected_video.download(quiet=False)
root = Tk()
my_youtube = YouTubeDownloader(root)
root.mainloop()
Yellowed Yacare