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