Guest User

Simple Youtube download script

a guest
Aug 15th, 2020
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. from tkinter import Tk, RIGHT, BOTH, RAISED, Text, TOP, BOTH, X, N, LEFT, StringVar, ANCHOR
  2. from tkinter.ttk import Frame, Button, Style, Label, Entry
  3. from tkinter.filedialog import askopenfile
  4. from tkinter.scrolledtext import ScrolledText
  5. import youtube_dl
  6. import sys
  7. import time
  8. import queue as Queue
  9. import os
  10. import subprocess
  11. import _thread as thread
  12.  
  13. ydl_opts = {'noplaylist': True, 'format' : r'bestvideo[height<=1080]+bestaudio',
  14.             'merge-output-format':True, 'outtmpl' : r'e:\temp music\videos\%(title)s.%(ext)s'}
  15.  
  16. queue = Queue.Queue(100)
  17.  
  18. class StdoutRedirector(object):
  19.     def __init__(self, text_widget):
  20.         self. text_space = text_widget
  21.  
  22.     def write(self, string):
  23.         self.text_space.insert('end', string)
  24.         self.text_space.see('end')
  25.  
  26.     def flush(self):
  27.         pass
  28.  
  29.     def isatty(self):
  30.         pass
  31.  
  32. class youtube(Frame):
  33.  
  34.     def __init__(self, parent):
  35.         self.parent = parent
  36.         self.root = parent
  37.         super().__init__()
  38.  
  39.         self.initUI()
  40.  
  41.     def initUI(self):
  42.  
  43.         self.url = StringVar()
  44.  
  45.         self.master.title("Youtube Downloader")
  46.         self.style = Style()
  47.         self.style.theme_use("default")
  48.  
  49.         # FRAME
  50.         frame1 = Frame(self)
  51.         frame1.pack(fill=X)
  52.  
  53.         lbl1 = Label(frame1, text="Url", width=6)
  54.         lbl1.pack(side=LEFT, padx=5, pady=5)
  55.  
  56.         entry1 = Entry(frame1, textvariable=self.url, width=50)
  57.         entry1.pack(fill=X, padx=5, expand=True)
  58.         entry1.bind('<Enter>', self.clip_paste )
  59.  
  60.         # FRAME
  61.         #frame2 = Frame(self)
  62.         #frame2.pack(fill=BOTH, expand=True)
  63.  
  64.         #lbl2 = Label(frame2, text="Output", width=6)
  65.         #lbl2.pack(side=LEFT, padx=2, pady=5)
  66.  
  67.         #text_box = ScrolledText(frame2,  wrap='word', height = 11, width=50)
  68.         #text_box.pack(side=LEFT, fill=BOTH, expand=True, padx=13)
  69.  
  70.         # FRAME
  71.         frame3 = Frame(self, relief=RAISED, borderwidth=1)
  72.         frame3.pack(fill=BOTH)
  73.  
  74.         self.pack(fill=BOTH, expand=True)
  75.  
  76.         closeButton = Button(self, text="Close", command=self.quit)
  77.         closeButton.pack(side=RIGHT, padx=5, pady=5)
  78.         okButton = Button(self, text="Get File", command=self.call_yt)
  79.         okButton.pack(side=RIGHT)
  80.  
  81.         #redir = StdoutRedirector(text_box)
  82.         #redirErr = StdoutRedirector(text_box)
  83.         #sys.stdout = redir
  84.         #sys.stderr = redirErr
  85.  
  86.     def clip_paste(self, event):
  87.         self.url.set(self.clipboard_get())
  88.  
  89.     def call_yt(self):
  90.         with youtube_dl.YoutubeDL(ydl_opts) as ydl:
  91.             ydl.download([self.url.get()])
  92.  
  93.         return
  94.  
  95. def main():
  96.  
  97.     root = Tk()
  98.                                     # w x h w h
  99.     #root.geometry("550x500+600+300")
  100.     root.geometry("400x80+800+700")
  101.     app = youtube(root)
  102.     root.mainloop()
  103.  
  104.  
  105. if __name__ == '__main__':
  106.     main()
  107.  
Advertisement
Add Comment
Please, Sign In to add comment