-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresolution_downloader.py
executable file
·263 lines (246 loc) · 15 KB
/
resolution_downloader.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
from format_converter import *
from link_parser import *
from thumbnail_preview_window import *
from ConverTube import *
import os
import sys
import subprocess
from PySide2 import *
#Use the ffmpeg cli program for windows version.
#Must have ffmpeg.exe and its dependencies in the same folder as the main python script
#The ffmpeg-python lib only returns a TypeError stating that it can't find any
#file in the Windows filesystem
#Adding the ffmpeg\bin folder to the system-wide and user environment variables
#then running that does that same thing
class ResolutionDownloader(QRunnable):
def __init__(self, yt_link, resolution_selector, format_selector):
super().__init__()
self.yt_link = yt_link
self.resolution_selector = resolution_selector
self.format_selector = format_selector
self.fmt_cvrter_thread = QThreadPool()
def run(self):
entered_link = [self.yt_link]
video = YouTube(str(entered_link))
if self.resolution_selector == "144p":
video_stream = video.streams.get_by_itag(17)
file_name = os.path.abspath(video_stream.download())
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, file_name)
self.fmt_cvrter_thread.start(format_converter)
elif self.resolution_selector == "240p":
print("240p has been selected!")
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(133)
video_name = os.path.abspath(video_stream.download())
video_codec = ffmpeg.input(video_name)
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.abspath(audio_stream.download())
audio_codec = ffmpeg.input(audio_name)
ffmpeg_conversion = ffmpeg.concat(video_codec, audio_codec, v=1, a=1).output(video_name[:-4] + "(1).mp4")
ffmpeg.run(ffmpeg_conversion)
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(137)
video_name = os.path.basename(video_stream.download())
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.basename(audio_stream.download())
subprocess.call(["ffmpeg", "-i", video_name, "-i", audio_name, "-crf", "0", "-c:v", "copy",
"-c:a", "copy", "-strict", "-2", video_name[:-4] + "(1).mp4"])
media_container = os.path.abspath(video_name)
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif self.resolution_selector == "360p":
video_stream = video.streams.get_by_itag(18)
file_name = os.path.abspath(video_stream.download())
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, file_name)
self.fmt_cvrter_thread.start(format_converter)
elif self.resolution_selector == "480p":
print("480p has been selected")
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(135)
video_name = os.path.abspath(video_stream.download())
video_codec = ffmpeg.input(video_name)
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.abspath(audio_stream.download())
audio_codec = ffmpeg.input(audio_name)
ffmpeg_conversion = ffmpeg.concat(video_codec, audio_codec, v=1, a=1).output(video_name[:-4] + "(1).mp4")
ffmpeg.run(ffmpeg_conversion)
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(137)
video_name = os.path.basename(video_stream.download())
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.basename(audio_stream.download())
subprocess.call(["ffmpeg", "-i", video_name, "-i", audio_name, "-q:v", "0", "-map",
"0:v", "-map", "1:a", video_name[:-4] + "(1).mp4"])
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif self.resolution_selector == "720p":
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(22)
file_name = os.path.abspath(video_stream.download())
format_converter = FormatConverter(self.format_selector, file_name)
self.fmt_cvrter_thread.start(format_converter)
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 # 5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(22)
file_name = os.path.abspath(video_stream.download())
format_converter = FormatConverter(self.format_selector, file_name)
self.fmt_cvrter_thread.start(format_converter)
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 # 5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
elif self.resolution_selector == "1080p":
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(137)
video_name = os.path.abspath(video_stream.download())
video_codec = ffmpeg.input(video_name)
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.abspath(audio_stream.download())
audio_codec = ffmpeg.input(audio_name)
ffmpeg_conversion = ffmpeg.concat(video_codec, audio_codec, v=1, a=1).output(video_name[:-4] + "(1).mp4")
ffmpeg.run(ffmpeg_conversion)
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(137)
video_name = os.path.basename(video_stream.download())
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.basename(audio_stream.download())
subprocess.call(["ffmpeg", "-i", video_name, "-i", audio_name, "-q:v", "0", "-map",
"0:v", "-map", "1:a", video_name[:-4] + "(1).mp4"])
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif self.resolution_selector == "1440p":
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(400)
video_name = os.path.abspath(video_stream.download())
video_codec = ffmpeg.input(video_name)
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.abspath(audio_stream.download())
audio_codec = ffmpeg.input(audio_name)
ffmpeg_conversion = ffmpeg.concat(video_codec, audio_codec, v=1, a=1).output(video_name[:-4] + "(1).mp4")
ffmpeg.run(ffmpeg_conversion)
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(400)
video_name = os.path.basename(video_stream.download())
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.basename(audio_stream.download())
subprocess.call(["ffmpeg", "-i", video_name, "-i", audio_name, "-q:v", "0", "-map",
"0:v", "-map", "1:a", video_name[:-4] + "(1).mp4"])
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif self.resolution_selector == "2160p":
if sys.platform == "linux" or sys.platform == "linux2":
video_stream = video.streams.get_by_itag(401)
video_name = os.path.abspath(video_stream.download())
video_codec = ffmpeg.input(video_name)
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.abspath(audio_stream.download())
audio_codec = ffmpeg.input(audio_name)
ffmpeg_conversion = ffmpeg.concat(video_codec, audio_codec, v=1, a=1).output(video_name[:-4] + "(1).mp4")
ffmpeg.run(ffmpeg_conversion)
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)
elif sys.platform == "win32":
video_stream = video.streams.get_by_itag(137)
video_name = os.path.basename(video_stream.download())
audio_stream = video.streams.get_by_itag(251)
audio_name = os.path.basename(audio_stream.download())
subprocess.call(["ffmpeg", "-i", video_name, "-i", audio_name, "-q:v", "0", "-map",
"0:v", "-map", "1:a", video_name[:-4] + "(1).mp4"])
media_container = os.path.abspath(video_name[:-4] + "(1).mp4")
system_tray_icon = QIcon(u":/icons/assets/CT_app_icon.ico")
duration = 5000 #5 seconds
tray = QSystemTrayIcon(system_tray_icon)
tray.show()
tray.showMessage("ConverTube", "Finished downloading " + video_stream.title, system_tray_icon, duration)
format_converter = FormatConverter(self.format_selector, media_container)
self.fmt_cvrter_thread.start(format_converter)
os.remove(video_name)
os.remove(audio_name)