-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube-download-gui.py
151 lines (115 loc) · 5.43 KB
/
youtube-download-gui.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import re
import os
import moviepy.editor as mp
from pytube import YouTube
from pytube import Playlist
from pytube import Channel
from tkinter import *
def opcao1():
# LABEL INTERFACE GRÁFICA #
text_downloadsimples["text"] = "Para baixar um vídeo do YouTube informe a URL"
# LABEL INTERFACE GRÁFICA #
print("Para baixar um vídeo do YouTube informe a URL")
link = input("Informe a URL do seu vídeo: ")
yt = YouTube(link)
download_type = int(input(
"\n1 - Para baixar o vídeo; \n2 - Para baixar apenas o audio (.MP3).\n -> "))
if (download_type == 1):
print(f'Downloading {yt.title} WAIT')
baixando = yt.streams.get_highest_resolution()
baixando.download()
elif (download_type == 2):
print(f'Downloading {yt.title} WAIT')
baixando = yt.streams.filter(only_audio=True)
baixando[0].download('temp')
folder = "temp"
for file in os.listdir(folder):
if re.search('mp4', file):
mp4_path = os.path.join(folder, file)
mp3_path = os.path.join('.', os.path.splitext(file)[0]+'.mp3')
new_file = mp.AudioFileClip(mp4_path)
new_file.write_audiofile(mp3_path)
os.remove(mp4_path)
else:
print("OPAÇÃO INVALIDA, TENTE NOVAMENTE")
def opcao2():
# LABEL INTERFACE GRÁFICA #
text_playlist["text"] = "-- ATENÇÃO --\nPara baixar vídeos de uma playlist a URL deve ter o seguinte formato:\nhttps://www.youtube.com/playlist?list=ID_PLAYLIST\n"
# LABEL INTERFACE GRÁFICA #
print("Para baixar vídeos de uma Playlist do YouTube\n")
print("-- ATENÇÃO --\nPara baixar vídeos de uma playlist a URL deve ter o seguinte formato:\nhttps://www.youtube.com/playlist?list=ID_PLAYLIST\n")
linkplaylist = input("Informe a URL da sua Playlist: ")
p = Playlist(linkplaylist)
download_type = int(input(
"\n1 - Para baixar os vídeos; \n2 - Para baixar apenas os audios (.MP3).\n -> "))
if (download_type == 1):
print(f'Playlist name: {p.title}')
qtd = int(input("Informe quantos vídeos quer baixar dessa playlist: "))
for video in p.videos[:qtd]:
print(f'Downloading {p.title} WAIT')
video.streams.first().download()
print("Download de", qtd, " vídeos concluído!")
elif (download_type == 2):
print(f'Playlist name: {p.title}')
qtd = int(input("Informe quantos vídeos quer baixar dessa playlist: "))
for video in p.videos[:qtd]:
print(f'Downloading {p.title} WAIT')
video.streams.first().download('temp')
convertendo()
print("Download de", qtd, "vídeos concluído!")
else:
print("OPAÇÃO INVALIDA, TENTE NOVAMENTE")
def opcao3():
# LABEL INTERFACE GRÁFICA #
text_channel["text"] = "-- ATENÇÃO --\nPara baixar vídeos de uma playlist a URL deve ter o seguinte formato:\nhhttps://www.youtube.com/c/CHANNEL_NAME"
# LABEL INTERFACE GRÁFICA #
print("Para baixar vídeos de um Channel do YouTube\n")
print("-- ATENÇÃO --\nPara baixar vídeos de uma playlist a URL deve ter o seguinte formato:\nhhttps://www.youtube.com/c/CHANNEL_NAME\n")
linkchannel = input("Informe a URL do seu vídeo: ")
c = Channel(linkchannel)
download_type = int(input(
"\n1 - Para baixar os vídeos; \n2 - Para baixar apenas os audios (.MP3).\n -> "))
if (download_type == 1):
print(f'Downloading: {c.channel_name}')
qtd = int(input("Informe quantos vídeos quer baixar desse canal: "))
for video in c.videos[:qtd]:
print(f'Downloading {c.channel_name} WAIT')
video.streams.first().download()
print("Download de", qtd, " vídeos concluído!")
elif (download_type == 2):
print(f'Downloading: {c.channel_name}')
qtd = int(input("Informe quantos vídeos quer baixar desse canal: "))
for video in c.videos[:qtd]:
print(f'Downloading {c.channel_name} WAIT')
video.streams.first().download('temp')
convertendo()
print("Download de", qtd, "vídeos concluído!")
else:
print("OPAÇÃO INVALIDA, TENTE NOVAMENTE")
def convertendo():
folder = "temp"
for file in os.listdir(folder):
if re.search('3gpp', file):
temp_path = os.path.join(folder, file)
root_path = os.path.join('.', os.path.splitext(file)[0]+'.mp3')
new_file = mp.AudioFileClip(temp_path)
new_file.write_audiofile(root_path)
os.remove(temp_path)
## INTERFACE GRÁFICA ##
window = Tk()
window.title("YouTube-Download")
text_index = Label(window, text="Escolha uma das opções abaixo").grid(
column=0, row=0)
btn_opcao1 = Button(window, text="Download simples",
command=opcao1).grid(column=0, row=1)
text_downloadsimples = Label(window, text="").grid(column=0, row=4)
btn_opcao2 = Button(window, text="Playlist",
command=opcao2).grid(column=0, row=2)
text_playlist = Label(window, text="").grid(column=0, row=4)
btn_opcao3 = Button(window, text="Channel",
command=opcao3).grid(column=0, row=3)
text_channel = Label(window, text="").grid(column=0, row=4)
window.mainloop()
#opcoes = { 1:opcao1, 2:opcao2, 3:opcao3}
#escolha = int(input("\n--> Escolha uma opção <-- \n 1 - Download simples; \n 2 - Para download de uma playlist; \n 3 - Para download de um canal. \n-> "))
#opcoes.get(escolha)()