|
| 1 | +from tkinter import * |
| 2 | +import subprocess |
| 3 | +import requests |
| 4 | + |
| 5 | + |
| 6 | +def Invalid_URL(): |
| 7 | + """ Sets Status bar label to error message """ |
| 8 | + Status["text"] = "Invalid URL..." |
| 9 | + Status["fg"] = "red" |
| 10 | + |
| 11 | + |
| 12 | +def Download_vid(): |
| 13 | + """ Validates link and Downloads Video """ |
| 14 | + Download_Window.delete("0.0", "end") |
| 15 | + global URL_Val |
| 16 | + url = URL_Val.get() |
| 17 | + |
| 18 | + Status["text"] = "Downloading..." |
| 19 | + Status["fg"] = "green" |
| 20 | + |
| 21 | + # Validate input |
| 22 | + if not "twitter.com" in url: |
| 23 | + Invalid_URL() |
| 24 | + return |
| 25 | + response = requests.get(url) |
| 26 | + if not response.status_code == 200: |
| 27 | + Invalid_URL() |
| 28 | + response.close() |
| 29 | + return |
| 30 | + response.close() |
| 31 | + |
| 32 | + with subprocess.Popen("youtube-dl {} --no-cache-dir".format(url), stdout=subprocess.PIPE, shell=True, universal_newlines=True) as Process: |
| 33 | + for line in Process.stdout: |
| 34 | + Download_Window.insert(END, line) |
| 35 | + main.update_idletasks() |
| 36 | + |
| 37 | + Status["text"] = "Finished!!" |
| 38 | + Status["fg"] = "green" |
| 39 | + |
| 40 | + |
| 41 | +# <----- GUI Code Block Start -----> |
| 42 | +main = Tk() |
| 43 | +main.title("Twitter Video Downloader") |
| 44 | +main.geometry("600x400") |
| 45 | + |
| 46 | +URL_Label = Label(main, text="Enter Twitter Video URL:", anchor=W, font=("Calibri", 9)) |
| 47 | +URL_Label.place(x=30, y=20) |
| 48 | + |
| 49 | +URL_Val = StringVar() |
| 50 | +URL_Input = Entry(main, textvariable=URL_Val, font=("Calibri", 9)) |
| 51 | +URL_Input.place(x=60, y=50, width=400) |
| 52 | + |
| 53 | +Download_button = Button(main, text="Download", font=("Calibri", 9), command=Download_vid) |
| 54 | +Download_button.place(x=250, y=80, width=100) |
| 55 | + |
| 56 | +Download_Window = Text(main, font=("Calibri", 9), bg="black", fg="white", bd=1, relief=SUNKEN, wrap=WORD) |
| 57 | +Download_Window.insert(END, "Welcome to Twitter Video Downloader, Provide a Twitter video link in the above box and click download to start the process. :D") |
| 58 | +Download_Window.place(x=30, y=120, width=530, height=250) |
| 59 | + |
| 60 | +Status = Label(main, text="Hello!! :D", fg="orange", font=("Calibri", 9), bd=1, relief=SUNKEN, anchor=W, padx=3) |
| 61 | +Status.pack(side=BOTTOM, fill=X) |
| 62 | + |
| 63 | +main.mainloop() |
| 64 | +# <----- GUI Code Block End -----> |
0 commit comments