-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
727 lines (727 loc) · 56.6 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
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
import re
import os
import json
import time
import requests
import warnings
from typing import Any
from typing import Dict
from typing import List
from typing import Tuple
from st import Speedtest
import concurrent.futures
from pytube import YouTube
from typing import Literal
from typing import Optional
from pytube import Playlist
from termcolor import colored
from urllib.error import HTTPError
from http.client import IncompleteRead
from pytube.exceptions import PytubeError
warnings.filterwarnings("ignore", category=UserWarning)
BASE_DIR: str = 'U-YDT'
LOG_FILE_PATH: str = f'{BASE_DIR}/log/log.json'
def banner1() -> None:
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⡖⡄⠀⠀⢀⣀⢤⢤⢤⢤⢤⢤⣄⣄⣄⣠⣀⣀⣀⢀", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⢀⣀⣤⣤⣤⣄⣀⠀⠀⣠⣶⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⢀⢯⢢⢠⡪⡳⠽⠝⠝⠽⠽⠽⠽⠺⢺⢺⢾⢿⢾⣿⣿⣿⣶⣤⡀⠀⠀⠀⢀⢴⢕⠁", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⡀⡀⠀⠀⠀⠀⠀⠀⠀", 'red', 'on_black', ['bold']) + colored("⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣷⡄⠀⠀⠀⠀⠀⢀⣀⣄⣤⣤⣠⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⢝⢼⢸⠊⡄⠄⡀⢂⠐⠠⠠⠐⡈⡐⡐⡐⠔⣌⢜⢻⣿⣿⣳⢯⢆⠀⢠⢮⢣⠃", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣠⣶⣿⣿⣿⣿⣿⣿⣶⣤⡀⠀⠀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠁⠉⠙⠻⢿⣿⣿⣿⣿⣿⡄⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⠀⠀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⢠⢰⢣⠳⠀⡀⢂⡰⡴⣬⡀⠅⢂⢐⣄⣆⠌⠌⡂⡃⣺⣟⣞⢾⣝⣗⠀⡇⠇⠁", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⡿⠿⠿⠿⠿⠿⠿⠿⠿⢿⣿⣦⡀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⡿⠿⠋⢠⣾⣿⣿⣿⣿⣿⡏⣻⣿⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⢔⢱⢑⠕⡕⠀⡀⢲⢽⣝⣞⡆⠂⢄⣗⢷⢽⢽⠀⡂⠂⢼⡺⣮⣳⣳⡳⣕⢬", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠨⣿⣿⣷⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠋⠈⠀⠀⢀⣿⣿⣿⢛⢛⢛⢿⡇⣺⡟⡛⡛⠟⣿⣿⣧⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠢⡑⢅⢣⡃⠀⡀⠘⣗⣗⠗⠅⠂⡐⢽⢽⢽⠝⡀⢂⠁⡾⣝⣞⢾⢸⢹⢪⢯⢣", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⣿⣿⣿⡇⠀⠀⢸⣶⣄⡀⠀⠀⠨⣿⣿⣿⡇", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⡇⣺⣿⣿⡙⠇⡺⢹⣿⣿⡇⢽⣿⣿⡀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠈⠢⢱⢡⢃⢰⡀⠠⠀⢀⠈⡀⠂⠀⠄⠉⠁⠂⢐⠠⢀⣟⣞⢮⢯⢊⢎⠪⡪⠂", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢘⣿⣿⣿⡇⠀⠀⢸⣿⠟⠃⠀⠀⠨⣿⣿⣿⡇", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⡇⣺⣿⣿⣿⣦⣴⣿⣿⣿⡇⢽⣿⣿⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠈⡎⡎⡢⡠⡠⡐⣀⡀⡄⡀⡁⡠⢈⢀⠁⢌⢡⢜⢮⣪⣫⡫⡢⠂⠑", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣿⡇⠀⠀⠈⠀⠀⠀⠀⠀⢘⣿⣿⣿⠁", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣿⣇⠺⡿⡿⡿⡿⡿⡿⡿⡿⠇⣽⣿⠇⠀", 'green', 'on_black', ['bold']) + colored("⠠⣴⣲⢤⢤⣀⠀⠀⠀⠀⠀⠀⠱⡱⡱⡨⢢⢑⠔⡅⢇⢕⢱⢑⠕⡕⢍⠕⡕⡕⡕⡕⡕⡕⡕⠁", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⣧⣤⣤⣤⣤⣤⣤⣤⣤⣼⣿⡿⠃⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣿⣷⣶⣶⣶⣶⣶⣶⣶⣶⣿⡿⠃⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠕⡝⡽⣽⣺⢽⣳⢦⢦⢄⡀⠀⠈⠊⠮⢸⡰⡑⡕⡱⡘⢌⢎⠪⡊⡎⡪⢢⠣⡑⢕⠱⠑", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⢿⠋⠁⠀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠻⢿⢿⣿⣿⢿⠿⠻⠑⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠈⢐⠱⢱⢹⢝⢾⢽⢽⡪⡪⡣⡂⠀⠀⡀⡄⡬⢬⠬⡬⡢⡢⣕⢔⢔⢌⢔⡁⠊⠀⠀⠀⢀⢀⢀", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠘⠙⠙⠛⠙⠙⠈⠀⠀⠀⠀⠀", 'red', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'green', 'on_black', ['bold']) + colored("⠀⠀⠀⠈⠐⢡⠃⢇⢏⠟⡚⢎⢎⠎⡠⡪⡪⡪⡪⡣⣫⡪⣯⡻⡮⣯⡳⣕⢕⢭⢣⢂⠀⢜⢮⡳⣕⢕⢦⢄", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠈⠐⠀⠡⠈⠂⠈⢠⠣⡱⡑⡕⡕⡕⡵⣝⢮⡻⡺⣪⡻⡮⡧⡣⡣⡣⡀⢕⠵⣝⢮⣳⢯⣟⣦⣀", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢈⠢⡑⢜⠌⡎⡪⡪⡳⡹⡸⡸⡸⡪⡪⡪⡪⡪⡂⠐⡑⢭⡻⣾⢽⣺⣺⣺⣲⡄", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⢤⣤⡤⠀⠀⠀⠀⠀⠀⢠⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⣶⣤⡀⠀⠀⠀⠀⣠⠒⠁⠀⢀⡠⠤⣤⣤⡤⠤⠤⠤⣤⣄⡀⠀⠀⠀⠀⢀⠤⠤⠤⠤⠤⣤⣤⠤⠤⠤⠴⡆", 'light_magenta', 'on_black', ['bold']) + colored("⠨⡂⡆⡒⡆⡇⡎⢜⢜⢜⢜⢼⢜⢞⢞⢮⢮⢮⡪⡀⠀⠈⠆⡹⠸⡝⡾⣞⣞⡾⡽⣧", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⣄⠀⠀⡼⠁⠀⠀⡐⠁⠀⠀⢽⣿⡇⠀⠀⠀⠀⠙⣿⣶⡀⠀⠀⡏⠀⠀⠀⠀⠀⣿⣿⠇⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⡇⡪⢪⢪⢪⢪⡊⡎⡎⡎⡮⡫⡫⡳⡳⡳⡕⡕⠀⠀⠀⠀⠈⠈⠜⡘⠜⡝⢽⢽⢽⠅", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣆⣼⠁⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⠸⣿⣿⡀⠀⠁⠀⠀⠀⠀⠀⣿⣿⡃⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⢱⠨⡊⡎⡎⡎⡆⡣⡣⡣⡫⡪⡪⡪⡪⡪⡪⡊⠀⠀⠀⠀⠀⠀⠀⠀⠁⠈⠀⠈", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⠀⢸⡧⠀⠀⠀⢀⣀⣀⣀⣀⣀⠀⠀⠀⠀⠀⠀⠨⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⠨⣿⣿⡂⠀⠀⠀⠀⠀⠀⠀⣿⣿⡃⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⢳⠨⡊⢎⢎⢎⢄⢕⢜⢜⢜⢜⢜⢜⢜⠜", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⣇⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠉⠉⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⣿⣿⠅⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⠀⠀⢸⣿⡿⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡅⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠱⡨⠢⡑⢕⢕⢕⢕⢕⢕⢕⢕⢕⠑", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⢿⣿⡄⠀⠀⠀⠀⢀⡾⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⠅⠀⠀⠀⠀⠀⠀⠀⠀⢽⣿⡇⠀⠀⠀⢀⣰⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡅⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠈⠪⢐⢑⠔⡑⢜⢐⠕⡘⠔", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠳⠲⠒⠚⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠐⠛⠛⠓⠓⠚⠚⠙⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠛⠛⠓⠀⠀⠀", 'light_magenta', 'on_black', ['bold']) + colored("⠀⠀⠀⠀⠀⠀⠀⠀⠈⠈⠂⠑⠀⠁⠀⠀⠀Version : U.1.0.6", 'light_cyan', 'on_black', ['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭| By Unkn0wn2603 |⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭", "green", 'on_black'))
print("\n")
def banner2() -> None:
print(colored("""
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⣀⠀⠀⣤⡀⠀⠀⠀⠀⠀ ⢰⡄ ⢀⣀⣠⣤⣤⣤⣤⣤⣤⣤⣤⣤⣄⣀⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣀⡀⠀⠀⠀⠀⡶⡿⡿⣿⣿⣿⣿⣾⣿⣷⡀⠀⠀ ⢸⡺⢀⡮⠿⠽⠻⠻⠻⠟⠿⠿⡿⡿⡿⣿⣿⣿⣷⣦⡀ ⢀⣴⢏⢏⡦
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣦⡀⠀⠀⠀⠀⠀⠀⠉⢛⣿⣿⣿⣿⠀⠀ ⣠⣴⣶⣶⣶⣶⣦⣄ ⠂⢯⡳⡃⠑⠄⠂⡁⢂⠡⠨⢐⢐⠰⡘⡴⣙⣿⣿⣿⣿⡄⢀⡿⢕⠁
⠀⠀⠀⠀⠀⠀⠀⠀⣴⣿⡏⠀⢀⠀⠀⠀⠁⣿⣿⡄⠀⠀⠀⠀⠀⠀⠘⠛⠋⠉⠀⠀ ⠀⣾⣿⣿⣿ ⢸⣿⣿⣿⣧ ⡠⡪⡎⣗ ⠡⢰⣽⣾⣔⠠⢈⣴⣶⣦⠊⡐⠡⣿⣿⡿⣷⣇⡪⠊
⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢸⣿⡦⠀⠀⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣴⠋⠈⠀⠀⣿⣿⣿⣍⠃⠘⣩⣿⣿⣿ ⢀⠣⢣⠣⡚ ⠄⢿⢿⣽⠗ ⢺⣿⣽⡾⠂⢂⢁⣿⣟⣿⡳⣿⢽⡦
⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⡇⠀⠘⠉⠀⠀⠀⣿⣿⠇⠀⠤⣤⣤⡄⠀⠀⠀⠀⠀⢸⡏⠀⠀⠀⠀⢻⣿⣿⣿⣓⣚⣿⣿⣿⡟ ⠑⠅⣎⢎⢠⠠ ⠍⠑⠈⡀⠂⠙⠚⢁⠁⡂⢸⣯⣟⣷⠹⡸⡱⠝
⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣷⣶⣶⣶⣶⣶⣶⣿⠏⠀⠀⠨⣿⣿⡂⠀⠀⠀⠀⠀⢽⡇⠀⠀⠀⠀ ⠙⠻⠿⠿⠿⠿⠟⠋ ⢱⢱⠥⡡⡠⡐⣀⢂⣀⢄⣁⡈⣀⣐⡣⣫⢷⣻⡺⡕⠈⠂⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠛⠻⠿⠿⠛⠋⠀⠀⠀⠀⠨⣿⣿⡂⠀⠀⠀⠀⠀⢽⡇⠀⠀⠀⠀ ⡶⣶⣶⣴⣄⣀ ⠈⠺⡜⡜⡸⡨⡢⡣⡪⡪⡢⡣⡣⡪⡪⡳⡹⣪⢺⠉
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠨⣿⣿⡂⠀⠀⠀⠀⠀⢽⡇⠀⠀⠀⠀ ⠨⠹⡻⡿⣿⣿⣿⣯⣖⣄⡀⠈⠘⠊⠎⠮⠜⢌⣊⡊⠪⠊⢎⠪⠸⡘⠌⠈
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⣿⡆⠀⠀⠀⠀⠀⣿⠃⠀⠀⠀⠀ ⠈⠈⡪⢫⢻⢻⢿⡺⣺⡪⢀⢔⡜⣎⢯⡫⣗⡷⣽⡯⣟⡮⡮⡦⡀ ⢠⢦⣖⢦⢄
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠻⣿⣤⣀⣀⣠⠾⠋⠀⠀⠀⠀⠀⠀ ⠁⠘⠈⠆⠕⠁⡪⡕⡕⡕⣇⢿⣻⣿⣳⢿⣻⣽⡳⣝⣝⠄⡹⣽⢾⢽⣽⣷⣄
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⢰⠱⡘⢜⠜⡬⡹⢝⢟⢎⢯⢳⠳⡝⡎⡎⡇⠨⡊⢿⣿⣿⣿⣿⣷⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢶⣦⣀⠀⠀⠀⢀⡴⠋⠁⢀⣠⡤⣤⣤⡤⠤⠤⣤⣄⣀⠀⠀⠀⠀⣠⡤⠤⠤⠤⣤⣤⡤⠤⠤⣴ ⡇⡆⡧⣪⢦⢣⢳⢱⢝⡾⡽⣽⣳⢯⢯⡂ ⠘⠔⡱⠻⡿⣿⣿⣿⣷⡀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣿⣧⡀⢠⡞⠁⠀⣐⠉⠀⠀⣿⣿⡇⠀⠀⠀⠙⣿⣷⣄⠀⢸⠁⠀⠀⠀⠀⣿⣿⡇⠀⠀⠈ ⢇⢎⢎⢮⢳⡣⡣⡳⣹⣺⢽⡳⡽⡽⡵⠁ ⠑⠑⠩⠋⠟⠻⠃
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⣿⣶⡿⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⢘⣿⣷⡂⠀⠃⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀ ⠘⣆⠣⡣⡳⣕⠱⡱⡱⣏⢷⠽⣝⢞⠊
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠨⣿⣿⡃⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⢐⣿⣿⡂⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀ ⠘⢜⠌⡎⢎⢇⢯⢺⢕⡝⣝⢜⠊
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠨⣿⣿⡂⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⠀⠀ ⠑⢜⢌⠪⡊⢎⠪⡊⠆⠁
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⣿⣿⣂⠀⠀⠀⠀⠀⠀⢀⣿⣿⣇⣀⣀⣤⡾⠿⠃⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣇⠀⠀⠀ ⠁⠁⠁⠁ Version : U.1.0.6
""", "cyan", attrs=['bold']))
print("\n")
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛⣛", "green", 'on_black', attrs=['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿", "red", 'on_black', attrs=['bold']))
print(colored("⠀⠀⠀⠀⠀⠀⠀⠀⠀⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭| By Unkn0wn2603 |⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭⣭", "green", 'on_black', attrs=['bold']))
print("\n")
def banner() -> None:
if os.name == 'nt':
os.system('cls')
banner1()
elif os.name == 'posix':
os.system('clear')
banner2()
else:
banner1()
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def select_stream(yt: YouTube, quality: str) -> Optional[Any]:
filters: Dict[str, Any] = {
"audio": lambda: yt.streams.filter(only_audio=True).order_by('abr').desc().first(),
"128kbps": lambda: yt.streams.filter(only_audio=True, abr="128kbps").first(),
"160kbps": lambda: yt.streams.filter(only_audio=True, abr="160kbps").first(),
"360p": lambda: yt.streams.filter(res="360p", progressive=True).first(),
"720p": lambda: yt.streams.filter(res="720p", progressive=True).first(),
"1080p": lambda: yt.streams.filter(res="1080p").first(),
"2k": lambda: yt.streams.filter(res="1440p").first(),
"4k": lambda: yt.streams.filter(res="2160p").first(),
"8k": lambda: yt.streams.filter(res="4320p").first(),
"highest": lambda: yt.streams.get_highest_resolution()
}
return filters.get(quality, filters["highest"])()
def quality_input() -> str:
quality_map: Dict[str, str] = {
'1': 'audio',
'2': '128kbps',
'3': '160kbps',
'4': '360p',
'5': '720p',
'6': '1080p',
'7': '2k',
'8': '4k',
'9': '8k',
'10': 'highest'
}
print(colored(' [i] Select the download quality:', 'cyan', attrs=['bold']))
options: List[str] = [
"Audio only (best quality)",
"Audio 128kbps",
"Audio 160kbps",
"360p",
"720p",
"1080p",
"2k",
"4k",
"8k",
"Highest available quality"
]
for i, desc in enumerate(options, start=1):
print(colored(f' [{i}] {desc}', 'cyan'))
quality_choice: str = input(colored(' [?] Enter the number of your choice: ', 'cyan', attrs=['bold'])).strip()
return quality_map.get(quality_choice, 'highest')
def load_json(file_path: str) -> Optional[Any]:
if os.path.exists(file_path):
with open(file_path, 'r') as f:
return json.load(f)
return None
def save_json(file_path: str, data: Any) -> None:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
with open(file_path, 'w') as file:
json.dump(data, file, indent=4)
def update_log(log_file: str, log_data: Dict[str, Any]) -> None:
data: List[Dict[str, Any]] = load_json(log_file) or []
data.append(log_data)
save_json(log_file, data)
def sanitize_title(filename: str) -> str:
# Remove or replace characters that are invalid in names
filename = re.sub(r'[<>:"/\\|?*]', '', filename)
# Optionally, truncate the filename to a reasonable length
return filename[:200]
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
# Flags for detailed output
SERVER_PRINT = True # Print server details
CLIENT_PRINT = True # Print client details
LATENCY_PRINT = True # Print latency details
DOWNLOAD_PRINT = True # Print download speed
UPLOAD_PRINT = True # Print upload speed
def print_bold_line(title=None, status=None, title_color=None, status_color=None, title_on_color=None, status_on_color=None, oncolor=[]):
"""Helper function to print title and status in bold and optionally colored messages on the same line."""
oncolor.append('bold')
if status==None:
if title==None:
print()
else:
print(colored(title, title_color, title_on_color, attrs=oncolor))
if status!=None:
if title!=None:
if title_color:
title = colored(title, title_color, title_on_color, attrs=oncolor)
else:
title = colored(title, attrs=oncolor)
if status_color:
status = colored(status, status_color, status_on_color, attrs=oncolor)
else:
status = colored(status, attrs=oncolor)
print(f"{title}: {status}")
def speed_test():
banner()
# Creating an instance of Speedtest
speedtest = Speedtest()
# Perform the speed test
best_server = speedtest.get_best_server()
results = speedtest.results.dict()
# Print the results based on the flags
if CLIENT_PRINT:
client_info = results['client']
print_bold_line()
print_bold_line(" ---------------------------------- [ CLIENT SIDE INFORMATIONS ] ----------------------------------", title_color='yellow')
print_bold_line(" [c] Client IP ----------------------------------------- ", client_info['ip'], 'yellow', 'yellow')
print_bold_line(" [c] Client ISP ---------------------------------------- ", client_info['isp'], 'yellow', 'yellow')
print_bold_line(" [c] Client Country ------------------------------------ ", client_info['country'], 'yellow', 'yellow')
print_bold_line(" [c] Client Latitude ----------------------------------- ", client_info['lat'], 'yellow', 'yellow')
print_bold_line(" [c] Client Longitude ---------------------------------- ", client_info['lon'], 'yellow', 'yellow')
if SERVER_PRINT:
print_bold_line()
print_bold_line(" ---------------------------------- [ SERVER SIDE INFORMATIONS ] ----------------------------------", title_color='blue')
print_bold_line(" [s] Server ID ----------------------------------------- ", best_server['id'], 'blue', 'blue')
print_bold_line(" [s] Server Host --------------------------------------- ", best_server['host'], 'blue', 'blue')
print_bold_line(" [s] Server Sponsor ------------------------------------ ", best_server['sponsor'], 'blue', 'blue')
print_bold_line(" [s] Server Distance ----------------------------------- ", f"{best_server['d']:.2f} km", 'blue', 'blue')
print_bold_line(" [s] Server Location ----------------------------------- ", f"{best_server['name']}, {best_server['country']}", 'blue', 'blue')
print_bold_line(" [s] Server Latitude ----------------------------------- ", best_server['lat'], 'blue', 'blue')
print_bold_line(" [s] Server Longitude ---------------------------------- ", best_server['lon'], 'blue', 'blue')
speedtest.download()
results = speedtest.results.dict()
if DOWNLOAD_PRINT:
print_bold_line()
print_bold_line(" --------------------------------- [ SPEED RELATED INFORMATIONS ] ---------------------------------", title_color='cyan')
download_speed = results['download'] / 1e6 # Convert to Mbps
dl_speed = f"{download_speed:.4f}" # Format to 4 decimal places
if download_speed > 90: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'green')
elif download_speed > 70: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'blue')
elif download_speed > 45: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'light_yellow')
elif download_speed > 30: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'yellow')
elif download_speed > 20: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'light_magenta')
elif download_speed > 15: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'magenta')
elif download_speed > 10: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'light_red')
else: print_bold_line(" [d] Download Speed ------------------------------------ ", f"{dl_speed} Mbps", 'cyan', 'red')
speedtest.upload()
results = speedtest.results.dict()
if UPLOAD_PRINT:
upload_speed = results['upload'] / 1e6 # Convert to Mbps
up_speed = f"{upload_speed:.4f}" # Format to 4 decimal places
if upload_speed > 90: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'green')
elif upload_speed > 70: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'blue')
elif upload_speed > 45: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'light_yellow')
elif upload_speed > 30: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'yellow')
elif upload_speed > 20: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'light_magenta')
elif upload_speed > 15: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'magenta')
elif upload_speed > 10: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'light_red')
else: print_bold_line(" [u] Upload Speed -------------------------------------- ", f"{up_speed} Mbps", 'cyan', 'red')
if LATENCY_PRINT:
ping = results['ping']
if ping < 10: print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'green')
elif ping < 50: print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'blue')
elif ping < 100:print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'light_yellow')
elif ping < 300:print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'yellow')
elif ping < 500:print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'light_magenta')
elif ping < 700:print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'magenta')
elif ping < 900:print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'light_red')
else: print_bold_line(" [p] Latency ------------------------------------------- ", f"{ping:.4f} ms", 'cyan', 'red')
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def download_single_video(video_url: str) -> None:
banner()
quality: str = quality_input()
try:
yt: YouTube = YouTube(video_url)
print(colored(f' [i] Downloading video: {yt.title} ({quality})', color="blue", attrs=["bold"]))
download_dir: str = os.path.join(BASE_DIR, 'videos', quality)
os.makedirs(download_dir, exist_ok=True)
log_dir: str = os.path.join(BASE_DIR, 'videos', 'log')
os.makedirs(log_dir, exist_ok=True)
stream: Optional[Any] = select_stream(yt, quality)
if stream:
log_data: Dict[str, Any] = {
'title': yt.title,
'quality': quality,
'video_url': video_url,
'duration': yt.length,
'author': yt.author,
'views': yt.views,
'publish_date': str(yt.publish_date),
'others': {
'description': yt.description,
'keywords': yt.keywords,
'thumbnail_url': yt.thumbnail_url,
'rating': yt.rating
}
}
log_file_path1: str = os.path.join(log_dir, 'all_log.json')
log_file_path2: str = os.path.join(log_dir, f'{quality}_log.json')
update_log(log_file_path1, log_data)
update_log(log_file_path2, log_data)
stream.download(output_path=download_dir)
print(colored(f' [i] Download complete: {yt.title}', color="green", attrs=["bold"]))
else:
print(colored(f' [!] No stream found for {yt.title} with quality {quality}', color="red", attrs=["bold"]))
except Exception as e:
print(colored(f' [!] Failed to download {video_url}: {e}', color="red", attrs=["bold"]))
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def file_exists(folder: str, filename: str, expected_size: int) -> bool:
file_path = os.path.join(folder, filename)
if os.path.exists(file_path):
if os.path.getsize(file_path) == expected_size:
return True
else:
print(colored(f' [!] File {filename} exists but size does not match. It will be overwritten.', color="yellow", attrs=["bold"]))
return False
def playlist_download_video(video: Any, folder: str, idx: int, total_videos: int, log_file: str, log_data: Dict[str, List[str]], quality: str, max_retries: int = 3) -> None:
for attempt in range(max_retries):
try:
yt: YouTube = YouTube(video.watch_url)
print(colored(f' [i] Downloading video ({idx}/{total_videos}): {video.title} ({quality})', color="blue", attrs=["bold"]))
stream: Optional[Any] = select_stream(yt, quality)
if stream:
# Sanitize the filename to avoid invalid characters and truncation issues
safe_title = sanitize_title(video.title)
filename = f'{idx:03d} - {safe_title}.mp4'
file_path = os.path.join(folder, filename)
# Check if file already exists with the same title and size
if file_exists(folder, filename, stream.filesize):
print(colored(f' [i] File already exists: {filename}', color="green", attrs=["bold"]))
log_data['completed'].append(video.watch_url)
save_json(log_file, log_data)
return
# Download the video
stream.download(output_path=folder, filename=filename)
print(colored(f' [i] Download complete: {video.title}', color="green", attrs=["bold"]))
log_data['completed'].append(video.watch_url)
save_json(log_file, log_data)
return
else:
print(colored(f' [!] No stream found for {video.title} with quality {quality}', color="red", attrs=["bold"]))
if video.watch_url not in log_data['not_completed']:
log_data['not_completed'].append(video.watch_url)
save_json(log_file, log_data)
return
except IncompleteRead as e:
print(colored(f' [!] IncompleteRead error on attempt {attempt + 1} for {video.title}: {e}', color="yellow", attrs=["bold"]))
if attempt < max_retries - 1:
time.sleep(2) # Wait a bit before retrying
except Exception as e:
print(colored(f' [!] Failed to download {video.title} on attempt {attempt + 1}: {e}', color="red", attrs=["bold"]))
if attempt < max_retries - 1:
time.sleep(2) # Wait a bit before retrying
# If all attempts fail, log the failure
if video.watch_url not in log_data['not_completed']:
log_data['not_completed'].append(video.watch_url)
save_json(log_file, log_data)
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def playlist_video_exists(video: Any, log_data: Dict[str, List[str]]) -> bool:
return video.watch_url in log_data['completed']
def playlist_create_directories(playlist_title: str, quality: str) -> Tuple[str, str, str]:
base_dir: str = 'playlist'
playlist_folder: str = os.path.join(BASE_DIR, base_dir, playlist_title)
quality_folder: str = os.path.join(playlist_folder, quality)
log_folder: str = os.path.join(playlist_folder, 'download_data')
os.makedirs(quality_folder, exist_ok=True)
os.makedirs(log_folder, exist_ok=True)
return playlist_folder, quality_folder, log_folder
def playlist_get_video_links(playlist_url: str, links_file: str) -> List[str]:
links_data: Optional[Dict[str, Any]] = load_json(links_file)
if links_data and 'video_urls' in links_data:
return links_data['video_urls']
playlist: Playlist = Playlist(playlist_url)
video_urls: List[str] = [video.watch_url for video in playlist.videos]
save_json(links_file, {'video_urls': video_urls})
return video_urls
def download_playlist_videos(playlist_url: str) -> None:
banner()
playlist: Playlist = Playlist(playlist_url)
safe_title = sanitize_title(playlist.title)
print(colored(f' [i] Downloading playlist: {safe_title}', color="magenta", attrs=["bold"]))
quality: str = quality_input()
playlist_folder, quality_folder, log_folder = playlist_create_directories(safe_title, quality)
links_file: str = os.path.join(log_folder, 'links.json')
log_file: str = os.path.join(log_folder, f'{quality}.json')
video_urls: List[str] = playlist_get_video_links(playlist_url, links_file)
log_data: Dict[str, List[str]] = load_json(log_file) or {'completed': [], 'not_completed': []}
total_videos: int = len(video_urls)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [
executor.submit(playlist_download_video, YouTube(video_url), quality_folder, idx, total_videos, log_file, log_data, quality)
for idx, video_url in enumerate(video_urls, start=1) if not playlist_video_exists(YouTube(video_url), log_data)
]
for future in concurrent.futures.as_completed(futures):
future.result()
print(colored(' [i] All downloads complete!', 'green'))
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def channel_load_log(log_file: str) -> Dict[str, List[str]]:
if os.path.exists(log_file):
with open(log_file, 'r') as f:
return json.load(f)
return {'completed': [], 'not_completed': []}
def channel_select_stream(yt: YouTube, quality: str) -> Optional[Any]:
return select_stream(yt, quality)
def channel_save_log(log_file: str, log_data: Dict[str, List[str]]) -> None:
with open(log_file, 'w') as f:
json.dump(log_data, f, indent=4)
def download_channel_video(video_url: str, folder: str, idx: int, total_videos: int, log_file: str, log_data: Dict[str, List[str]], quality: str) -> None:
try:
yt: YouTube = YouTube(video_url)
print(colored(f' [i] Downloading video ({idx}/{total_videos}): {yt.title} ({quality})', color="blue", attrs=["bold"]))
stream: Optional[Any] = channel_select_stream(yt, quality)
if stream:
stream.download(output_path=folder)
print(colored(f' [i] Download complete: {yt.title} ', color="green", attrs=["bold"]))
log_data['completed'].append(video_url)
else:
print(colored(f' [!] No stream found for {yt.title} with quality {quality}', color="red", attrs=["bold"]))
if video_url not in log_data['not_completed']:
log_data['not_completed'].append(video_url)
channel_save_log(log_file, log_data)
except Exception as e:
print(colored(f' [!] Failed to download {yt.title}: {e} ', color="red", attrs=["bold"]))
if video_url not in log_data['not_completed']:
log_data['not_completed'].append(video_url)
channel_save_log(log_file, log_data)
def channel_get_video_urls(api_key: str, channel_id: str, channel_name: str) -> List[str]:
base_video_url: str = 'https://www.youtube.com/watch?v='
base_search_url: str = 'https://www.googleapis.com/youtube/v3/search?'
links_file: str = os.path.join(BASE_DIR, 'channels', channel_name, 'download_data', 'links.json')
if os.path.exists(links_file):
with open(links_file, 'r') as f:
data = json.load(f)
print(colored(' [i] There is info and links of this channel in local db, not fetching from google:', 'cyan', attrs=['bold']))
return data['video_urls']
first_url: str = f'{base_search_url}key={api_key}&channelId={channel_id}&part=snippet,id&order=date&maxResults=50'
video_urls: List[str] = []
url: str = first_url
while True:
response = requests.get(url).json()
for item in response['items']:
if item['id']['kind'] == "youtube#video":
video_urls.append(base_video_url + item['id']['videoId'])
try:
next_page_token: str = response['nextPageToken']
url = f'{first_url}&pageToken={next_page_token}'
except KeyError:
break
os.makedirs(os.path.join(BASE_DIR, 'channels', channel_name, 'download_data'), exist_ok=True)
with open(links_file, 'w') as f:
json.dump({'video_urls': video_urls}, f, indent=4)
print(colored(' [i] Fetching from google info and links of this channel:', 'cyan', attrs=['bold']))
return video_urls
def channel_video_exists(video_url: str, log_data: Dict[str, List[str]]) -> bool:
return video_url in log_data['completed']
def download_channel(api_key: str, channel_id: str, channel_name: str) -> None:
banner()
channel_name: str = sanitize_title(channel_name)
video_urls: List[str] = channel_get_video_urls(api_key, channel_id, channel_name)
log_folder: str = os.path.join(BASE_DIR, 'channels', channel_name, 'download_data')
if not os.path.exists(log_folder):
os.makedirs(log_folder)
quality: str = quality_input()
log_file: str = os.path.join(log_folder, f'{quality}.json')
log_data: Dict[str, List[str]] = channel_load_log(log_file)
if log_data['completed'] or log_data['not_completed']:
print(colored(' [i] Some records found for this channel and quality.', 'cyan'))
print(colored(' [i] There are some incomplete downloads.', 'cyan'))
print(colored(' [i] What would you like to do?', 'cyan'))
print(colored(' [1] Download only incomplete items from the JSON database.', 'cyan'))
print(colored(' [2] Recheck all videos from Google data.', 'cyan'))
choice: str = input(colored(" [?] Enter your choice (default: 1): ", 'blue')).strip()
if choice == '2':
log_data = {'completed': [], 'not_completed': []}
else:
print(colored(' [i] Downloading incomplete items from the JSON database.', 'cyan'))
else:
print(colored(' [i] No downloading records found for this channel and quality.', 'cyan'))
print(colored(' [i] Proceeding to fetch video URLs from Google data.', 'cyan'))
total_videos: int = len(video_urls)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = []
for idx, video_url in enumerate(video_urls, start=1):
if channel_video_exists(video_url, log_data):
print(colored(f' [~] Skipping already downloaded video ({idx}/{total_videos}): {video_url} ',
color="yellow", attrs=["bold"]))
continue
futures.append(
executor.submit(download_channel_video, video_url, os.path.join(BASE_DIR, 'channels', channel_name, quality), idx, total_videos, log_file, log_data, quality))
for future in concurrent.futures.as_completed(futures):
future.result()
print(colored(' [i] All downloads complete!', 'green'))
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def normalize_video_url(url: str) -> str:
base_url: str = 'https://www.youtube.com/watch?v='
if len(url) == 11:
return base_url + url
if not url.startswith('https://www.youtube.com/'):
if url.startswith('https://'):
url = url.replace('https://', 'https://www.')
elif url.startswith('youtube.com/'):
url = 'https://www.' + url
else:
url = 'https://www.youtube.com/' + url.split('youtube.com/')[1]
video_id_index: int = url.find('v=')
if video_id_index != -1:
base_url = url[:video_id_index + len('v=')]
video_id: str = url[video_id_index + len('v='):]
end_of_id_index: int = video_id.find('&')
if end_of_id_index != -1:
video_id = video_id[:end_of_id_index]
return base_url + video_id
return url
def fetch_video_title(normalized_url: str) -> Optional[str]:
try:
video: YouTube = YouTube(normalized_url)
return video.title
except (PytubeError, HTTPError) as e:
print(f"Failed to fetch video title: {e}")
return None
def normalize_playlist_url(url: str) -> str:
base_url: str = 'https://www.youtube.com/playlist?list='
if url.startswith('PL'):
return base_url + url
if not url.startswith('https://www.youtube.com/'):
if url.startswith('https://'):
url = url.replace('https://', 'https://www.')
elif url.startswith('youtube.com/'):
url = 'https://www.' + url
else:
url = 'https://www.youtube.com/' + url.split('youtube.com/')[1]
playlist_id_index: int = url.find('list=')
if playlist_id_index != -1:
base_url = url[:playlist_id_index + len('list=')]
playlist_id: str = url[playlist_id_index + len('list='):]
end_of_id_index: int = playlist_id.find('&')
if end_of_id_index != -1:
playlist_id = playlist_id[:end_of_id_index]
return base_url + playlist_id
return url
def fetch_playlist_title(normalized_url: str) -> Optional[str]:
try:
playlist: Playlist = Playlist(normalized_url)
safe_title = sanitize_title(playlist.title)
return safe_title
except (PytubeError, HTTPError) as e:
print(f"Failed to fetch playlist title: {e}")
return None
def load_log() -> Dict[str, Any]:
return load_json(LOG_FILE_PATH) or {}
def save_log(log: Dict[str, Any]) -> None:
save_json(LOG_FILE_PATH, log)
"""################################################################################################################################################################
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
################################################################################################################################################################"""
def start_u_ydt() -> Literal[0, 9]:
log: Dict[str, Any] = load_log()
print(colored(" [i] What would you like to do ?", 'blue'))
print(colored(" [1] Channel download", 'cyan'))
print(colored(" [2] Playlist download", 'cyan'))
print(colored(" [3] Single Content download", 'cyan'))
print(colored(" [4] Check Previous downloads", 'cyan'))
print(colored(" [5] Check PInternet Speed", 'cyan'))
choice: str = input(colored(" [~] Choose an option: ", 'yellow')).strip()
if choice == '1':
api_key, channel_id, channel_name = handle_channel_input(log)
save_log(log)
download_channel(api_key, channel_id, channel_name)
return 0
elif choice == '2':
playlist_url: str = input(colored(" [~] Enter playlist URL or ID: ", 'yellow')).strip()
normalized_url: str = normalize_playlist_url(playlist_url)
playlist_title: str = handle_playlist_input(log, normalized_url)
save_log(log)
download_playlist_videos(normalized_url)
return 0
elif choice == '3':
single_content_url: str = input(colored(" [~] Enter single content URL or ID: ", 'yellow')).strip()
normalized_url: str = normalize_video_url(single_content_url)
video_title: str = handle_single_content_input(log, normalized_url)
save_log(log)
download_single_video(normalized_url)
return 0
elif choice == '4':
check_previous_downloads(log)
return 0
elif choice == '5':
speed_test()
return 0
return 9
def handle_channel_input(log: Dict[str, Any]) -> Tuple[str, str, str]:
if 'api_keys' in log and log['api_keys']:
api_key: str = select_api_key(log)
else:
api_key = input(colored(" [~] Enter new API key: ", 'yellow')).strip()
log['api_keys'] = [api_key]
channel_id: str = input(colored(" [~] Enter channel ID: ", 'yellow')).strip()
if 'channels' in log and channel_id in [c['channel_id'] for c in log['channels']]:
channel: Dict[str, str] = next(c for c in log['channels'] if c['channel_id'] == channel_id)
channel_name: str = channel['channel_name']
print(colored(f" [~] Channel exists in log, named: {channel_name}", 'yellow'))
else:
channel_name = input(colored(" [~] Enter channel name: ", 'yellow')).strip()
log.setdefault('channels', []).append({'channel_id': channel_id, 'channel_name': channel_name})
return api_key, channel_id, channel_name
def select_api_key(log: Dict[str, Any]) -> str:
print(colored(" [i] Available API keys:", 'blue'))
for i, api_key in enumerate(log['api_keys'], 1):
print(colored(f" [{i}] {api_key}", 'cyan'))
api_choice: str = input(colored(" [~] Choose an API key or enter 'new' to use a new API key: ", 'yellow')).strip()
if api_choice.isdigit() and 1 <= int(api_choice) <= len(log['api_keys']):
return log['api_keys'][int(api_choice) - 1]
else:
api_key: str = input(colored(" [~] Enter new API key: ", 'yellow')).strip()
log.setdefault('api_keys', []).append(api_key)
return api_key
def handle_playlist_input(log: Dict[str, Any], normalized_url: str) -> str:
if 'playlists' in log and normalized_url in [p['playlist_url'] for p in log['playlists']]:
playlist: Dict[str, str] = next(p for p in log['playlists'] if p['playlist_url'] == normalized_url)
playlist_title: str = playlist['playlist_title']
print(colored(f" [~] Playlist exists in log, named: {playlist_title}", 'yellow'))
else:
playlist_title: Optional[str] = fetch_playlist_title(normalized_url)
if playlist_title is None:
playlist_title = "Unknown Playlist"
log.setdefault('playlists', []).append({'playlist_url': normalized_url, 'playlist_title': playlist_title})
return playlist_title
def handle_single_content_input(log: Dict[str, Any], normalized_url: str) -> str:
if 'single_contents' in log and normalized_url in [v['video_url'] for v in log['single_contents']]:
video: Dict[str, str] = next(v for v in log['single_contents'] if v['video_url'] == normalized_url)
video_title: str = video['video_title']
print(colored(f" [~] The content exists in log, named: {video_title}", 'yellow'))
else:
video_title: Optional[str] = fetch_video_title(normalized_url)
if video_title is None:
video_title = "Unknown Video"
log.setdefault('single_contents', []).append({'video_url': normalized_url, 'video_title': video_title})
return video_title
def check_previous_downloads(log: Dict[str, Any]) -> None:
print(colored(" [i] Which type of previous downloads do you want to check?", 'blue'))
print(colored(" [1] Videos", 'cyan'))
print(colored(" [2] Playlists", 'cyan'))
print(colored(" [3] Channels", 'cyan'))
print(colored(" [4] All", 'cyan'))
check_choice: str = input(colored(" [~] Choose an option: ", 'yellow')).strip()
if check_choice == '1':
handle_check_videos(log)
elif check_choice == '2':
handle_check_playlists(log)
elif check_choice == '3':
handle_check_channels(log)
elif check_choice == '4':
handle_check_all(log)
def handle_check_videos(log: Dict[str, Any]) -> None:
if 'single_contents' in log:
print(colored(" [i] Previous video downloads:", 'blue'))
for i, video in enumerate(log['single_contents'], 1):
print(colored(f" [{i}] {video['video_title']} ({video['video_url']})", 'cyan'))
video_choice: int = int(input(colored(" [~] Enter the number of the video to download: ", 'yellow')).strip())
download_single_video(log['single_contents'][video_choice - 1]['video_url'])
def handle_check_playlists(log: Dict[str, Any]) -> None:
if 'playlists' in log:
print(colored(" [i] Previous playlist downloads:", 'blue'))
for i, playlist in enumerate(log['playlists'], 1):
print(colored(f" [{i}] {playlist['playlist_title']} ({playlist['playlist_url']})", 'cyan'))
playlist_choice: int = int(input(colored(" [~] Enter the number of the playlist to download: ", 'yellow')).strip())
download_playlist_videos(log['playlists'][playlist_choice - 1]['playlist_url'])
def handle_check_channels(log: Dict[str, Any]) -> None:
if 'channels' in log:
print(colored(" [i] Previous channel downloads:", 'blue'))
for i, channel in enumerate(log['channels'], 1):
print(colored(f" [{i}] {channel['channel_name']} ({channel['channel_id']})", 'cyan'))
channel_choice: int = int(input(colored(" [~] Enter the number of the channel to download: ", 'yellow')).strip())
channel: Dict[str, str] = log['channels'][channel_choice - 1]
api_key: str = select_api_key(log)
save_log(log)
download_channel(api_key, channel['channel_id'], channel['channel_name'])
def handle_check_all(log: Dict[str, Any]) -> None:
sn: int = 1
if 'single_contents' in log:
print(colored(" [i] Previous video downloads:", 'blue'))
for video in log['single_contents']:
print(colored(f" [{sn}] {video['video_title']} ({video['video_url']})", 'cyan'))
sn += 1
if 'playlists' in log:
print(colored(" [i] Previous playlist downloads:", 'blue'))
for playlist in log['playlists']:
print(colored(f" [{sn}] {playlist['playlist_title']} ({playlist['playlist_url']})", 'cyan'))
sn += 1
if 'channels' in log:
print(colored(" [i] Previous channel downloads:", 'blue'))
for channel in log['channels']:
print(colored(f" [{sn}] {channel['channel_name']} ({channel['channel_id']})", 'cyan'))
sn += 1
prev_choice: int = int(input(colored(" [~] Enter the number of the download to complete: ", 'yellow')).strip())
if prev_choice <= len(log.get('single_contents', [])):
download_single_video(log['single_contents'][prev_choice - 1]['video_url'])
elif prev_choice <= len(log.get('single_contents', [])) + len(log.get('playlists', [])):
download_playlist_videos(log['playlists'][prev_choice - len(log.get('single_contents', [])) - 1]['playlist_url'])
else:
index: int = prev_choice - len(log.get('single_contents', [])) - len(log.get('playlists', [])) - 1
channel_info: Dict[str, str] = log['channels'][index]
api_key: str = select_api_key(log)
save_log(log)
download_channel(api_key, channel_info['channel_id'], channel_info['channel_name'])
def main() -> None:
while True:
try:
banner()
x = start_u_ydt()
if x == 9:
input(colored("\n [!] Wrong input, why ? press enter to continue", 'red'))
continue
except Exception as e:
input(colored(f"\n [!] Error Occurred, Details: {e}", 'red'))
except KeyboardInterrupt:
input(colored("\n [?] Press Enter to exit: ", 'red'))
break
if input(colored("\n [?] Want to do some more things (y/n): ", 'red')).strip().lower() != 'y':
break
if __name__ == "__main__":
main()