Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import Tk, RIGHT, BOTH, RAISED, Text, TOP, BOTH, X, N, LEFT, StringVar, ANCHOR
- from tkinter.ttk import Frame, Button, Style, Label, Entry
- from tkinter.filedialog import askopenfile
- from tkinter.scrolledtext import ScrolledText
- import youtube_dl
- import sys
- import time
- import queue as Queue
- import os
- import subprocess
- import _thread as thread
- ydl_opts = {'noplaylist': True, 'format' : r'bestvideo[height<=1080]+bestaudio',
- 'merge-output-format':True, 'outtmpl' : r'e:\temp music\videos\%(title)s.%(ext)s'}
- queue = Queue.Queue(100)
- class StdoutRedirector(object):
- def __init__(self, text_widget):
- self. text_space = text_widget
- def write(self, string):
- self.text_space.insert('end', string)
- self.text_space.see('end')
- def flush(self):
- pass
- def isatty(self):
- pass
- class youtube(Frame):
- def __init__(self, parent):
- self.parent = parent
- self.root = parent
- super().__init__()
- self.initUI()
- def initUI(self):
- self.url = StringVar()
- self.master.title("Youtube Downloader")
- self.style = Style()
- self.style.theme_use("default")
- # FRAME
- frame1 = Frame(self)
- frame1.pack(fill=X)
- lbl1 = Label(frame1, text="Url", width=6)
- lbl1.pack(side=LEFT, padx=5, pady=5)
- entry1 = Entry(frame1, textvariable=self.url, width=50)
- entry1.pack(fill=X, padx=5, expand=True)
- entry1.bind('<Enter>', self.clip_paste )
- # FRAME
- #frame2 = Frame(self)
- #frame2.pack(fill=BOTH, expand=True)
- #lbl2 = Label(frame2, text="Output", width=6)
- #lbl2.pack(side=LEFT, padx=2, pady=5)
- #text_box = ScrolledText(frame2, wrap='word', height = 11, width=50)
- #text_box.pack(side=LEFT, fill=BOTH, expand=True, padx=13)
- # FRAME
- frame3 = Frame(self, relief=RAISED, borderwidth=1)
- frame3.pack(fill=BOTH)
- self.pack(fill=BOTH, expand=True)
- closeButton = Button(self, text="Close", command=self.quit)
- closeButton.pack(side=RIGHT, padx=5, pady=5)
- okButton = Button(self, text="Get File", command=self.call_yt)
- okButton.pack(side=RIGHT)
- #redir = StdoutRedirector(text_box)
- #redirErr = StdoutRedirector(text_box)
- #sys.stdout = redir
- #sys.stderr = redirErr
- def clip_paste(self, event):
- self.url.set(self.clipboard_get())
- def call_yt(self):
- with youtube_dl.YoutubeDL(ydl_opts) as ydl:
- ydl.download([self.url.get()])
- return
- def main():
- root = Tk()
- # w x h w h
- #root.geometry("550x500+600+300")
- root.geometry("400x80+800+700")
- app = youtube(root)
- root.mainloop()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment