Amazing-Python-Scripts

Форк
0
69 строк · 2.0 Кб
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:",
47
                  anchor=W, font=("Calibri", 9))
48
URL_Label.place(x=30, y=20)
49

50
URL_Val = StringVar()
51
URL_Input = Entry(main, textvariable=URL_Val, font=("Calibri", 9))
52
URL_Input.place(x=60, y=50, width=400)
53

54
Download_button = Button(main, text="Download", font=(
55
    "Calibri", 9), command=Download_vid)
56
Download_button.place(x=250, y=80, width=100)
57

58
Download_Window = Text(main, font=("Calibri", 9), bg="black",
59
                       fg="white", bd=1, relief=SUNKEN, wrap=WORD)
60
Download_Window.insert(
61
    END, "Welcome to Twitter Video Downloader, Provide a Twitter video link in the above box and click download to start the process. :D")
62
Download_Window.place(x=30, y=120, width=530, height=250)
63

64
Status = Label(main, text="Hello!! :D", fg="orange", font=(
65
    "Calibri", 9), bd=1, relief=SUNKEN, anchor=W, padx=3)
66
Status.pack(side=BOTTOM, fill=X)
67

68
main.mainloop()
69
# <----- GUI Code Block End ----->
70

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.