-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
212 lines (181 loc) · 5.73 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# Yes, I used a code beautifier...
import os as o
try:
import colorama
print("module 'colorama' is installed")
except ModuleNotFoundError:
print("module 'colorama' is not installed")
o.system("pip install colorama")
try:
import pytube
print("module 'pytube' is installed")
except ModuleNotFoundError:
print("module 'pytube' is not installed")
o.system("pip install pytube")
try:
import moviepy
print("module 'moviepy' is installed")
except ModuleNotFoundError:
print("module 'moviepy' is not installed")
o.system("pip install moviepy")
import time as t
import platform as p
from pytube import YouTube
from moviepy.editor import *
from colorama import init, Fore, Back, Style
rOS = p.system()
if rOS in ("Windows", "NT"):
init()
else:
pass
def osClear():
rOS = p.system()
if rOS in ("Windows", "NT"):
o.system("cls")
else:
o.system("clear")
def main():
osClear()
intro = open("intro.txt", "r")
print(intro.read())
link = input(f"{Back.BLACK}Paste the youtube link:{Style.RESET_ALL}\n> ")
osClear()
yt = YouTube(link)
osClear()
intro = open("intro.txt", "r")
pretitleVerify = input(
f"{intro.read()}\n{Back.BLACK}Is this the YouTube video's title? (y/n){Style.RESET_ALL}\n{yt.title}\n> "
)
titleVerify = pretitleVerify.lower()
if titleVerify == "y":
pass
elif titleVerify == "n":
osClear()
main()
elif titleVerify == "yes":
pass
elif titleVerify == "no":
osClear()
main()
else:
osClear()
intro = open("intro.txt", "r")
print(
f"{intro.read()}{Back.RED}Duh oh!.. Invalid response, restarting!..{Style.RESET_ALL}"
)
t.sleep(2)
osClear()
main()
osClear()
intro = open("intro.txt", "r")
print(intro.read())
prempChoice = input(
f"{Back.BLACK}Would you like to download as MP4 (Video) or MP3 (Audio)?{Style.RESET_ALL}\n> "
)
mpChoice = prempChoice.lower()
if mpChoice == "mp4":
try:
yt = (
yt.streams.filter(progressive=True, file_extension="mp4")
.order_by("resolution")
.desc()
.first()
)
yt.download("./")
except:
print(
f"A{Back.RED}n error has occured!... Maybe a connection timeout or the YouTube link is invalid!..{Style.RESET_ALL}"
)
t.sleep(2)
osClear()
main()
print(f"{Back.GREEN}Done! Saved into the current directory!..{Style.RESET_ALL}")
exit()
elif mpChoice == "mp3":
try:
yt = (
yt.streams.filter(progressive=True, file_extension="mp4")
.order_by("resolution")
.desc()
.first()
)
yt.download("./")
print(f"{Back.BLUE}Downloading the mp4...{Style.RESET_ALL}")
t.sleep(3)
print(
f"{Back.BLUE}Converting to mp3, this will take some time depending on the file size!..{Style.RESET_ALL}"
)
video = VideoFileClip(f"{yt.title}.mp4")
video.audio.write_audiofile(f"{yt.title}.mp3")
if o.path.exists(f"{yt.title}.mp4"):
o.remove(f"{yt.title}.mp4")
else:
pass
except:
print(
f"{Back.RED}An error has occured!... Maybe a connection timeout or the YouTube link is invalid!..{Style.RESET_ALL}"
)
t.sleep(2)
osClear()
main()
print(f"{Back.GREEN}Done! Saved into the current directory!..{Style.RESET_ALL}")
exit()
elif mpChoice == "video":
try:
yt = (
yt.streams.filter(progressive=True, file_extension="mp4")
.order_by("resolution")
.desc()
.first()
)
yt.download("./")
except:
print(
f"{Back.RED}An error has occured!... Maybe a connection timeout or the YouTube link is invalid!..{Style.RESET_ALL}"
)
t.sleep(2)
osClear()
main()
print(f"{Back.GREEN}Done! Saved into the current directory!..{Style.RESET_ALL}")
exit()
elif mpChoice == "audio":
try:
yt = (
yt.streams.filter(progressive=True, file_extension="mp4")
.order_by("resolution")
.desc()
.first()
)
yt.download("./")
print(f"{Back.BLUE}Downloading the mp4...{Style.RESET_ALL}")
t.sleep(3)
print(
f"{Back.BLUE}Converting to mp3, this will take some time depending on the file size!..{Style.RESET_ALL}"
)
video = VideoFileClip(f"{yt.title}.mp4")
video.audio.write_audiofile(f"{yt.title}.mp3")
if o.path.exists(f"{yt.title}.mp4"):
o.remove(f"{yt.title}.mp4")
else:
pass
except:
print(
f"{Back.RED}An error has occured!... Maybe a connection timeout or the YouTube link is invalid!..{Style.RESET_ALL}"
)
t.sleep(2)
osClear()
main()
print(f"{Back.GREEN}Done! Saved into the current directory!..{Style.RESET_ALL}")
exit()
else:
osClear()
print(f"{Back.RED}Duh oh!.. Invalid response, restarting!..{Style.RESET_ALL}")
t.sleep(2)
osClear()
main()
if __name__ == "__main__":
main()
#############################
# GitHub => russian-dev #
# Instagram => russian.devv #
#############################