-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (28 loc) · 1.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import PySimpleGUI as sg
from pytube import YouTube
sg.theme('DefaultNoMoreNagging')
layout = [
[sg.Text('Insira a URL do vídeo do YouTube:')],
[sg.Input(key='-URL-', size=(50, 1))],
[sg.Button('Download')]
]
window = sg.Window('Baixar Vídeo do YouTube', layout)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == 'Download':
url = values['-URL-']
try:
video = YouTube(url)
titulo = video.title
caminho_salvar = os.path.join(os.path.expanduser("~"), "Videos")
if not os.path.exists(caminho_salvar):
os.makedirs(caminho_salvar)
stream = video.streams.get_highest_resolution()
stream.download(output_path=caminho_salvar)
sg.popup(f'O vídeo "{titulo}" foi baixado com sucesso!', title='Download Concluído')
except Exception as e:
sg.popup_error(f'Ocorreu um erro durante o download:\n{str(e)}', title='Erro')
window.close()