-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
3211 lines (3036 loc) · 179 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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
from tkinter import *
from tkinter import filedialog, messagebox
import customtkinter
import pytube
from pytubefix import YouTube, Playlist, Search, extract, request
import pytubefix.request
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.formatters import SRTFormatter
import threading
from threading import Thread
import json
from PIL import Image
import urllib.request
import os
import io
import reprlib
import time
import subprocess
import webbrowser
import shlex
from sys import platform
import requests
# Get config prefences from JSON
def get_bg_theme():
try:
with open("theme_config.json", "r") as f:
theme = json.load(f)
return theme["bg_theme"]
except FileNotFoundError:
with open("_internal/theme_config.json", "r") as f:
theme = json.load(f)
return theme["bg_theme"]
def get_default_color():
try:
with open("theme_config.json", "r") as f:
theme = json.load(f)
return theme["default_color"]
except FileNotFoundError:
with open("_internal/theme_config.json", "r") as f:
theme = json.load(f)
return theme["default_color"]
# Set themes
customtkinter.set_appearance_mode(get_bg_theme())
customtkinter.set_default_color_theme(get_default_color())
# On closing
def onClosing():
# if messagebox.askokcancel("Quit", "Do you want to quit?"):
root.destroy()
# Create form
root = customtkinter.CTk()
width = 700
height = 460
x = (root.winfo_screenwidth() // 2) - (width // 2)
y = (root.winfo_screenheight() // 2) - (height // 2)
root.geometry(fr"{width}x{height}+{x}+{y}") # Centers the window
root.resizable(False, False)
if platform == "linux" or platform == "linux2": pass # Linux
else:
try: root.iconbitmap("YDICO.ico") # Windows
except TclError: root.iconbitmap("_internal/YDICO.ico") # Windows
root.title("YouTube Downloader")
customtkinter.CTkLabel(root, text = "YouTube Downloader", font = ("arial bold", 45)).place(x = 140 , y = 20)
# Link Entry Copy
def linkCopy():
start = link_entry.index("sel.first")
end = link_entry.index("sel.last")
to_copy = link_entry.get()[start:end]
root.clipboard_append(to_copy)
# Link Entry Cut
def linkCut():
start = link_entry.index("sel.first")
end = link_entry.index("sel.last")
to_copy = link_entry.get()[start:end]
root.clipboard_append(to_copy) # Get text from clipboard
try: # Delete the selected text
start = link_entry.index("sel.first")
end = link_entry.index("sel.last")
link_entry.delete(start, end)
except TclError:
pass # Nothing was selected, so paste won't delete
# Link Entry Paste
def linkPaste():
clipboard = root.clipboard_get() # Get text from clipboard
clipboard = clipboard.replace("\n", "\\n")
try: # delete the selected text, if any
start = link_entry.index("sel.first")
end = link_entry.index("sel.last")
link_entry.delete(start, end)
except TclError:
pass # Nothing was selected, so paste won't delete
link_entry.insert("insert", clipboard) # Insert the modified clipboard contents
# Right-Click menu
m = Menu(root, tearoff = 0)
m.add_command(label ="Cut", font = ("arial", 11), command = linkCut)
m.add_command(label ="Copy", font = ("arial", 11), command = linkCopy)
m.add_command(label ="Paste", font = ("arial", 11), command = linkPaste)
def linkRightClickMenu(event):
try: m.tk_popup(event.x_root, event.y_root)
finally: m.grab_release()
# Search Entry Copy
def searchCopy():
start = link_entry.index("sel.first")
end = link_entry.index("sel.last")
to_copy = link_entry.get()[start:end]
root.clipboard_append(to_copy)
# Search Entry Cut
def searchCut():
start = search_entry.index("sel.first")
end = search_entry.index("sel.last")
to_copy = search_entry.get()[start:end]
root.clipboard_append(to_copy) # Get text from clipboard
try: # Delete the selected text
start = search_entry.index("sel.first")
end = search_entry.index("sel.last")
search_entry.delete(start, end)
except TclError:
pass # Nothing was selected, so paste won't delete
# Search Entry Paste
def searchPaste():
clipboard = root.clipboard_get() # Get text from clipboard
clipboard = clipboard.replace("\n", "\\n")
try: # Delete the selected text, if any
start = search_entry.index("sel.first")
end = search_entry.index("sel.last")
search_entry.delete(start, end)
except TclError:
pass # Nothing was selected, so paste won't delete
search_entry.insert("insert", clipboard) # Insert the modified clipboard contents
# Right-Click menu
m2 = Menu(root, tearoff = 0)
m2.add_command(label ="Cut", font = ("arial", 11), command = searchCut)
m2.add_command(label ="Copy", font = ("arial", 11), command = searchCopy)
m2.add_command(label ="Paste", font = ("arial", 11), command = searchPaste)
def searchRightClickMenu(event):
try: m2.tk_popup(event.x_root, event.y_root)
finally: m2.grab_release()
# Paste link widgets
link_var = StringVar()
customtkinter.CTkLabel(root, text = "Paste Your URL Here", font = ("arial bold", 25)).place(x = 105 , y = 120)
link_entry = customtkinter.CTkEntry(root, width = 345, textvariable = link_var, corner_radius = 20)
link_entry.place(x = 100 , y = 160)
link_entry.bind("<Button-3>", linkRightClickMenu)
# Type keywords widgets
search_var = StringVar()
customtkinter.CTkLabel(root, text = "Type Your Keywords Here", font = ("arial bold", 25)).place(x = 105 , y = 220)
search_entry = customtkinter.CTkEntry(root, width = 345, textvariable = search_var, corner_radius = 20)
search_entry.place(x = 100 , y = 260)
search_entry.bind("<Button-3>", searchRightClickMenu)
def check_youtube_link(link):
video_pattern = re.compile(r"(https?://)?(www\.)?(youtube\.com/watch\?v=|youtu\.be/)[\w\-]+")
playlist_pattern = re.compile(r"(https?://)?(www\.)?youtube\.com/playlist\?list=[\w\-]+")
if playlist_pattern.match(link):
return "Playlist Link"
elif video_pattern.match(link):
return "Video Link"
else:
return "Invalid YouTube Link"
# Quality selections for downloads
quality_var = IntVar()
def downloadQualitySelect(quality):
url_text = link_var.get()
url_validaty = check_youtube_link(url_text)
if url_validaty == "Invalid YouTube Link":
whenError()
return messagebox.showerror(title = "URL is invalid", message = "Please enter a vaild URL.")
if quality == "Video: 1080p": quality_var.set(137)
elif quality == "Video: 720p": quality_var.set(22)
elif quality == "Video: 480p": quality_var.set(135)
elif quality == "Video: 360p": quality_var.set(18)
elif quality == "Video: 240p": quality_var.set(133)
elif quality == "Video: 144p": quality_var.set(160)
elif quality == "Audio: 160kbps": quality_var.set(251)
elif quality == "Audio: 128kbps": quality_var.set(140)
elif quality == "Audio: 70kbps": quality_var.set(250)
elif quality == "Audio: 50kbps": quality_var.set(249)
else: quality_var.set(0)
global link
link = link_var.get()
if url_validaty == "Playlist Link": threading.Thread(target = PlaylistWindow).start()
else: threading.Thread(target = DownlaodWindow).start()
loading_optionmenu = download_optionmenu
threading.Thread(target = Loading, args = (loading_optionmenu,)).start()
download_quality_list = ["Video: 1080p", "Video: 720p", "Video: 480p", "Video: 360p", "Video: 240p", "Video: 144p", "Audio: 160kbps", "Audio: 128kbps", "Audio: 70kbps", "Audio: 50kbps"]
download_optionmenu = customtkinter.CTkOptionMenu(root, width = 175, height = 35, font = ("arial bold", 25), values = download_quality_list, command = downloadQualitySelect, corner_radius = 15)
download_optionmenu.place(x = 460 , y = 155)
download_optionmenu.set("Download")
# Quality selections for search
quality_var = IntVar()
def searchQualitySelect(quality):
search_text = search_var.get()
if search_text == "":
whenError()
return messagebox.showerror(title = "Entry is Empty", message = "Please type something.")
elif len(search_text) < 3:
whenError()
return messagebox.showerror(title = "Characters Not Enough", message = "Please type at least 3 characters.")
if quality == "Video: 1080p": quality_var.set(137)
elif quality == "Video: 720p": quality_var.set(22)
elif quality == "Video: 480p": quality_var.set(135)
elif quality == "Video: 360p": quality_var.set(18)
elif quality == "Video: 240p": quality_var.set(133)
elif quality == "Video: 144p": quality_var.set(160)
elif quality == "Audio: 160kbps": quality_var.set(251)
elif quality == "Audio: 128kbps": quality_var.set(140)
elif quality == "Audio: 70kbps": quality_var.set(250)
elif quality == "Audio: 50kbps": quality_var.set(249)
else: quality_var.set(0)
global search
search = search_var.get()
loading_optionmenu = search_optionmenu
search_optionmenu.configure(corner_radius = 15)
threading.Thread(target = SearchWindow).start()
threading.Thread(target = Loading, args = (loading_optionmenu,)).start()
search_quality_list = ["Video: 1080p", "Video: 720p", "Video: 480p", "Video: 360p", "Video: 240p", "Video: 144p", "Audio: 160kbps", "Audio: 128kbps", "Audio: 70kbps", "Audio: 50kbps"]
search_optionmenu = customtkinter.CTkOptionMenu(root, width = 175, height = 35, font = ("arial bold", 25), values = search_quality_list, command = searchQualitySelect, corner_radius = 35)
search_optionmenu.place(x = 460 , y = 255)
search_optionmenu.set("Search")
# Appearance theme
def changeTheme(color):
color = color.lower()
themes_list = ["system", "dark", "light"]
if color in themes_list:
customtkinter.set_appearance_mode(color)
to_change = "bg_theme"
else:
customtkinter.set_default_color_theme(color)
customtkinter.CTkLabel(root, text = "(Restart to take full effect)", font = ("arial", 12)).place(x = 242 , y = 415)
to_change = "default_color"
try:
with open("theme_config.json", "r", encoding="utf8") as f:
theme = json.load(f)
with open("theme_config.json", "w", encoding="utf8") as f:
theme[to_change] = color
json.dump(theme, f, sort_keys = True, indent = 4, ensure_ascii = False)
except FileNotFoundError:
with open("_internal/theme_config.json", "r", encoding="utf8") as f:
theme = json.load(f)
with open("_internal/theme_config.json", "w", encoding="utf8") as f:
theme[to_change] = color
json.dump(theme, f, sort_keys = True, indent = 4, ensure_ascii = False)
customtkinter.CTkLabel(root, text = "Appearance Settings", font = ("arial bold", 19)).place(x = 34 , y = 340)
customtkinter.CTkLabel(root, text = "Theme Mode: ", font = ("arial", 15)).place(x = 27 , y = 375)
themes_menu = customtkinter.CTkOptionMenu(root, values = ["System", "Dark", "Light"], width = 110, command = changeTheme, corner_radius = 15)
themes_menu.place(x = 127 , y = 375)
themes_menu.set(get_bg_theme().title())
customtkinter.CTkLabel(root, text = "Default Color: ", font = ("arial", 15)).place(x = 27 , y = 415)
defaultcolor_menu = customtkinter.CTkOptionMenu(root, values = ["Blue", "Dark-blue", "Green"], width = 110, command = changeTheme, corner_radius = 15)
defaultcolor_menu.place(x = 127 , y = 415)
defaultcolor_menu.set(get_default_color().title())
# Loading labels dots loop
ploading_counter_var = StringVar()
customtkinter.CTkLabel(root, textvariable = ploading_counter_var, font = ("arial", 22)).place(x = 530 , y = 208)
def Loading(loading_optionmenu):
loading_optionmenu.set("Loading")
time.sleep(0.5)
while True:
if loading_optionmenu.get() == "Loading":
loading_optionmenu.set("Loading.")
time.sleep(0.5)
else: break
if loading_optionmenu.get() == "Loading.":
loading_optionmenu.set("Loading..")
time.sleep(0.5)
else: break
if loading_optionmenu.get() == "Loading..":
loading_optionmenu.set("Loading...")
time.sleep(0.5)
else: break
if loading_optionmenu.get() == "Loading...":
loading_optionmenu.set("Loading")
time.sleep(0.5)
else: break
# Downloading labels dots loop
def Downloading(downloading_var):
if downloading_var.get() == "Converting":
while True:
if downloading_var.get() == "Converting":
downloading_var.set("Converting.")
time.sleep(0.5)
else: break
if downloading_var.get() == "Converting.":
downloading_var.set("Converting..")
time.sleep(0.5)
else: break
if downloading_var.get() == "Converting..":
downloading_var.set("Converting...")
time.sleep(0.5)
else: break
if downloading_var.get() == "Converting...":
downloading_var.set("Converting")
time.sleep(0.5)
else: break
elif downloading_var.get() == "Merging":
while True:
if downloading_var.get() == "Merging":
downloading_var.set("Merging.")
time.sleep(0.5)
else: break
if downloading_var.get() == "Merging.":
downloading_var.set("Merging..")
time.sleep(0.5)
else: break
if downloading_var.get() == "Merging..":
downloading_var.set("Merging...")
time.sleep(0.5)
else: break
if downloading_var.get() == "Merging...":
downloading_var.set("Merging")
time.sleep(0.5)
else: break
elif downloading_var.get() == "Downloading audio":
while True:
if downloading_var.get() == "Downloading audio":
downloading_var.set("Downloading audio.")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading audio.":
downloading_var.set("Downloading audio..")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading audio..":
downloading_var.set("Downloading audio...")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading audio...":
downloading_var.set("Downloading audio")
time.sleep(0.5)
else: break
else:
downloading_var.set("Downloading")
time.sleep(0.5)
while True:
if downloading_var.get() == "Downloading":
downloading_var.set("Downloading.")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading.":
downloading_var.set("Downloading..")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading..":
downloading_var.set("Downloading...")
time.sleep(0.5)
else: break
if downloading_var.get() == "Downloading...":
downloading_var.set("Downloading")
time.sleep(0.5)
else: break
dont_change = ["Canceled", "Paused", "Finished", " "]
while True:
time.sleep(1)
if downloading_var.get() in dont_change: continue
else: Downloading(downloading_var)
# Integer -> time format
def to_hms(s):
m, s = divmod(s, 60)
h, m = divmod(m, 60)
return "{}:{:0>2}:{:0>2}".format(h, m, s)
# Clean file names
def clean_filename(name):
forbidden_chars = "*\\/\"'.|?:<>"
filename = ("".join([x if x not in forbidden_chars else " " for x in name])).replace(" ", " ").strip()
if len(filename) >= 176:
filename = filename[:170] + "..."
return filename
# When error happens return everything to normal in root
def whenError():
download_optionmenu.configure(state = "normal")
search_optionmenu.configure(state = "normal")
themes_menu.configure(state = "normal")
defaultcolor_menu.configure(state = "normal")
download_optionmenu.set("Download")
search_optionmenu.set("Search")
search_optionmenu.configure(corner_radius = 35)
ploading_counter_var.set("")
adv_quailty_button = customtkinter.CTkButton(root, text = "Advanced Quality Settings", width = 175, font = ("arial bold", 15), command = AdvancedWindow, corner_radius = 20)
adv_quailty_button.place(x = 460 , y = 375)
about_button = customtkinter.CTkButton(root, text = "About Developer", width = 175, font = ("arial bold", 15), command = AboutWindow, corner_radius = 20)
about_button.place(x = 460 , y = 415)
link_entry.configure(state = "normal")
search_entry.configure(state = "normal")
# When opens a new window from home page
def whenOpening():
download_optionmenu.configure(state = "disabled")
search_optionmenu.configure(state = "disabled")
themes_menu.configure(state = "disabled")
defaultcolor_menu.configure(state = "disabled")
ploading_counter_var.set("")
adv_quailty_button = customtkinter.CTkButton(root, text = "Advanced Quality Settings", width = 175, font = ("arial bold", 15), state = "disabled", corner_radius = 20)
adv_quailty_button.place(x = 460 , y = 375)
about_button = customtkinter.CTkButton(root, text = "About Developer", width = 175, font = ("arial bold", 15), state = "disabled", corner_radius = 20)
about_button.place(x = 460 , y = 415)
link_entry.configure(state = "disabled")
search_entry.configure(state = "disabled")
# Advanced Settings Window
def AdvancedWindow():
global advWindow
try:
advWindow.deiconify()
root.withdraw()
except:
# Form creating
def onClosing():
advWindow.destroy()
root.deiconify()
advWindow = customtkinter.CTkToplevel() # Toplevel object which will be treated as a new window
advWindow.withdraw()
advWindow.title("Advanced Quality Settings")
width = 700
height = 460
x = (advWindow.winfo_screenwidth() // 2) - (width // 2)
y = (advWindow.winfo_screenheight() // 2) - (height // 2)
advWindow.geometry(fr"{width}x{height}+{x}+{y}")
advWindow.maxsize(700, 460)
advWindow.minsize(700, 460)
if platform == "linux" or platform == "linux2": pass
else:
try: advWindow.iconbitmap("YDICO.ico") # Windows
except TclError: advWindow.iconbitmap("_internal/YDICO.ico") # Windows
advWindow.protocol("WM_DELETE_WINDOW", onClosing)
# CRF slider function
def crfSlider(num):
if num == 23: crf_var.set(fr"{int(num)} (Default)")
elif num == 0: crf_var.set(fr"{int(num)} (Loseless Quality)")
elif num == 51: crf_var.set(fr"{int(num)} (Lowest Quality)")
else: crf_var.set(int(num))
# Radiobuttons function
def radioDisableNormal():
if video_crf_or_bitrate.get() == "crfr":
crf_slider.configure(state = "normal")
bitrate_entry.configure(state = "disabled")
bitrate_entry.configure(border_color = "#565B5E")
else:
bitrate_entry.configure(state = "normal")
crf_slider.configure(state = "disabled")
if audio_quality_or_bitrate.get() == "bitrate":
abitrate_combobox.configure(state = "readonly")
aquality_combobox.configure(state = "disabled")
else:
aquality_combobox.configure(state = "readonly")
abitrate_combobox.configure(state = "disabled")
# Widgets vars
video_crf_or_bitrate = StringVar()
video_crf_or_bitrate.set("crfr")
crf_var = StringVar()
crf_var.set("23 (Default)")
audio_quality_or_bitrate = StringVar()
audio_quality_or_bitrate.set("bitrate")
bitrate_entry_var = StringVar()
# Widgets lists
profile_combobox_list = ["High", "Main (Default)", "Baseline"] # -profile [selected option]
tune_combobox_list = ["Film", "Animation", "Grain", "Still Image", "Fast Decode", "Zero Latency", "None (Default)"] # -tune [selected option]
preset_combobox_list = ["Ultrafast", "Superfast", "Veryfast", "Faster", "Fast", "Medium (Default)", "Slow"] # -preset [prselected optioneset]
format_combobox_list = ["MP4 (Default)", "M4A", "MKV"]
codec_combobox_list = ["H.264 (Default)", "H.265", "AV1", "MPEG-4"]
fps_combobox_list = ["5", "10", "15", "20", "23.976", "24", "30 (Default)", "40", "45", "50", "60"]
aformat_combobox_list = ["MP3 (Default)", "WAV", "AAC", "OPUS", "FLAC"]
abitrate_combobox_list = ["320", "192", "160", "128", "96", "70", "50"]
aquality_combobox_list = ["1", "2", "3", "4", "5", "6", "7", "8", "9"]
# Widgets placing
customtkinter.CTkLabel(advWindow, text = "Video Settings", font = ("arial bold italic", 30)).place(x = 8 , y = 13)
customtkinter.CTkLabel(advWindow, text = "Format:", font = ("arial bold", 20)).place(x = 20 , y = 55)
format_combobox = customtkinter.CTkComboBox(advWindow, width = 133, height = 26, values = format_combobox_list, corner_radius = 15, state = "readonly")
format_combobox._entry.configure(readonlybackground = format_combobox._apply_appearance_mode(format_combobox._fg_color))
format_combobox.set("MP4 (Default)")
format_combobox.place(x = 97 , y = 55)
customtkinter.CTkLabel(advWindow, text = "Encoder Tune:", font = ("arial bold", 20)).place(x = 360 , y = 125)
tune_combobox = customtkinter.CTkComboBox(advWindow, width = 137, height = 26, values = tune_combobox_list, corner_radius = 15, state = "readonly")
tune_combobox._entry.configure(readonlybackground = tune_combobox._apply_appearance_mode(tune_combobox._fg_color))
tune_combobox.set("None (Default)")
tune_combobox.place(x = 505 , y =125)
customtkinter.CTkLabel(advWindow, text = "Encoder Profile:", font = ("arial bold", 20)).place(x = 360 , y = 90)
profile_combobox = customtkinter.CTkComboBox(advWindow, width = 137, height = 26, values = profile_combobox_list, corner_radius = 15, state = "readonly")
profile_combobox._entry.configure(readonlybackground = profile_combobox._apply_appearance_mode(profile_combobox._fg_color))
profile_combobox.set("Main (Default)")
profile_combobox.place(x = 518 , y = 90)
customtkinter.CTkLabel(advWindow, text = "Encoder Preset:", font = ("arial bold", 20)).place(x = 360 , y = 55)
preset_combobox = customtkinter.CTkComboBox(advWindow, width = 150, height = 26, values = preset_combobox_list, corner_radius = 15, state = "readonly")
preset_combobox._entry.configure(readonlybackground = preset_combobox._apply_appearance_mode(preset_combobox._fg_color))
preset_combobox.set("Medium (Default)")
preset_combobox.place(x = 519 , y = 55)
customtkinter.CTkLabel(advWindow, text = "Codec:", font = ("arial bold", 20)).place(x = 20 , y = 90)
codec_combobox = customtkinter.CTkComboBox(advWindow, width = 138, height = 26, values = codec_combobox_list, corner_radius = 15, state = "readonly")
codec_combobox.place(x = 93 , y = 90)
codec_combobox._entry.configure(readonlybackground = codec_combobox._apply_appearance_mode(codec_combobox._fg_color))
codec_combobox.set("H.264 (Default)")
customtkinter.CTkLabel(advWindow, text = "Framerate (FPS):", font = ("arial bold", 20)).place(x = 20 , y = 125)
fps_combobox = customtkinter.CTkComboBox(advWindow, width = 120, height = 26, values = fps_combobox_list, corner_radius = 15, state = "readonly")
fps_combobox.place(x = 185 , y = 125)
fps_combobox._entry.configure(readonlybackground = fps_combobox._apply_appearance_mode(fps_combobox._fg_color))
fps_combobox.set("30 (Default)")
crf_radiobutton = customtkinter.CTkRadioButton(advWindow, text = "Constant Quality:", font = ("arial bold", 20), variable = video_crf_or_bitrate, value = "crfr", command = radioDisableNormal)
crf_radiobutton.place(x = 20 , y = 163)
customtkinter.CTkLabel(advWindow, textvariable = crf_var, font = ("arial", 17)).place(x = 520 , y = 161)
crf_slider = customtkinter.CTkSlider(advWindow, corner_radius = 15, width = 300, from_ = 0, to = 51, number_of_steps = 51, command = crfSlider)
crf_slider.place(x = 212 , y = 167)
crf_slider.set(23)
bitrate_radiobutton = customtkinter.CTkRadioButton(advWindow, text = "Total Bitrate (kbps):", font = ("arial bold", 20), variable = video_crf_or_bitrate, value = "bitrate", command = radioDisableNormal)
bitrate_radiobutton.place(x = 20 , y = 198)
bitrate_entry = customtkinter.CTkEntry(advWindow, textvariable = bitrate_entry_var, width = 100, height = 26, corner_radius = 15, state = "disabled")
bitrate_entry.place(x = 238 , y = 198)
customtkinter.CTkLabel(advWindow, text = "Audio Settings", font = ("arial bold italic", 30)).place(x = 8 , y = 238)
customtkinter.CTkLabel(advWindow, text = "Format:", font = ("arial bold", 20)).place(x = 20 , y = 280)
aformat_combobox = customtkinter.CTkComboBox(advWindow, width = 133, height = 26, values = aformat_combobox_list, corner_radius = 15, state = "readonly")
aformat_combobox._entry.configure(readonlybackground = aformat_combobox._apply_appearance_mode(aformat_combobox._fg_color))
aformat_combobox.set("MP3 (Default)")
aformat_combobox.place(x = 96 , y = 280)
abitrate_radiobutton = customtkinter.CTkRadioButton(advWindow, text = "Bitrate:", font = ("arial bold", 20), variable = audio_quality_or_bitrate, value = "bitrate", command = radioDisableNormal)
abitrate_radiobutton.place(x = 20 , y = 318)
abitrate_combobox = customtkinter.CTkComboBox(advWindow, width = 80, height = 26, values = abitrate_combobox_list, corner_radius = 15, state = "readonly")
abitrate_combobox._entry.configure(readonlybackground = abitrate_combobox._apply_appearance_mode(abitrate_combobox._fg_color))
abitrate_combobox.set("320")
abitrate_combobox.place(x = 121 , y = 316)
aquality_radiobutton = customtkinter.CTkRadioButton(advWindow, text = "Quality:", font = ("arial bold", 20), variable = audio_quality_or_bitrate, value = "quality", command = radioDisableNormal)
aquality_radiobutton.place(x = 20 , y = 353)
aquality_combobox = customtkinter.CTkComboBox(advWindow, width = 90, height = 26, values = aquality_combobox_list, corner_radius = 15, state = "disabled")
aquality_combobox._entry.configure(readonlybackground = aquality_combobox._apply_appearance_mode(aquality_combobox._fg_color))
aquality_combobox.place(x = 125 , y = 351)
# Switch stuff
global switch_value
switch_value = "video and audio"
def switchFunction():
global switch_value
if switch_value == "video and audio":
switch_value = "audio only"
format_combobox.configure(state = "disabled")
codec_combobox.configure(state = "disabled")
fps_combobox.configure(state = "disabled")
crf_slider.configure(state = "disabled")
bitrate_entry.configure(state = "disabled")
crf_radiobutton.configure(state = "disabled")
bitrate_radiobutton.configure(state = "disabled")
preset_combobox.configure(state = "disabled")
tune_combobox.configure(state = "disabled")
profile_combobox.configure(state = "disabled")
elif switch_value == "audio only":
switch_value = "video and audio"
format_combobox.configure(state = "readonly")
codec_combobox.configure(state = "readonly")
fps_combobox.configure(state = "readonly")
if video_crf_or_bitrate.get() == "crfr": crf_slider.configure(state = "normal")
else: bitrate_entry.configure(state = "normal")
crf_radiobutton.configure(state = "normal")
bitrate_radiobutton.configure(state = "normal")
preset_combobox.configure(state = "normal")
tune_combobox.configure(state = "normal")
profile_combobox.configure(state = "normal")
# Placing the switch and labels
customtkinter.CTkLabel(advWindow, text = "Audio Only", font = ("arial", 15)).place(x = 27 , y = 417)
switch = customtkinter.CTkSwitch(advWindow, text = "", command = switchFunction)
switch.place(x = 110 , y = 420)
switch.select()
customtkinter.CTkLabel(advWindow, text = "Video & Audio", font = ("arial", 15)).place(x = 154 , y = 417)
# Cancel
def cancelButton():
advWindow.destroy()
root.deiconify()
# Reset everything
def resetButton():
switch.select()
if switch_value == "audio only": switchFunction()
crf_slider.configure(state = "normal")
bitrate_entry.configure(state = "disabled")
abitrate_combobox.configure(state = "normal")
aquality_combobox.configure(state = "disabled")
format_combobox.set("MP4 (Default)")
codec_combobox.set("H.264 (Default)")
fps_combobox.set("30 (Default)")
preset_combobox.set("Medium (Default)")
tune_combobox.set("None (Default)")
profile_combobox.set("Main (Default)")
video_crf_or_bitrate.set("crfr")
crfSlider(23)
bitrate_entry_var.set("")
aformat_combobox.set("MP3 (Default)")
audio_quality_or_bitrate.set("bitrate")
abitrate_combobox.set("320")
aquality_combobox.set("")
# Save the ffmpeg command
def okButton():
global ffmpeg_command, advanced_quality_settings, advanced_extention, fps
fps = "30"
ffmpeg_command = 'ffmpeg -i "input"'
format_combobox.configure(border_color = "#565B5E")
bitrate_entry.configure(border_color = "#565B5E")
aformat_combobox.configure(border_color = "#565B5E")
if switch_value == "video and audio":
if format_combobox.get() == "MP4 (Default)": advanced_extention = "mp4"
else: advanced_extention = format_combobox.get().lower()
if codec_combobox.get() == "H.264 (Default)": codec = "libx264"
elif codec_combobox.get() == "H.265": codec = "libx265"
elif codec_combobox.get() == "AV1": codec = "libaom-av1"
elif codec_combobox.get() == "MPEG-4": codec = "mpeg4"
ffmpeg_command = ffmpeg_command + f' -c:v {codec}'
if fps_combobox.get() == "30 (Default)": fps = "30"
else: fps = fps_combobox.get()
ffmpeg_command = ffmpeg_command + f' -filter:v fps=fps={fps}'
if aformat_combobox.get() == "MP3 (Default)": format_codec = "libmp3lame"
elif aformat_combobox.get() == "AAC": format_codec = "aac"
elif aformat_combobox.get() == "OPUS": format_codec = "libopus"
elif aformat_combobox.get() == "FLAC": format_codec = "flac"
if format_combobox.get() == "M4A" and aformat_combobox.get() == "FLAC":
format_combobox.configure(border_color = "red")
aformat_combobox.configure(border_color = "red")
return messagebox.showerror(title = "Formats Not Compatible", message = "M4A Container doesn't support FLAC format.")
if profile_combobox.get() == "Main (Default)": profile = "main"
else: profile = profile_combobox.get().lower()
ffmpeg_command = ffmpeg_command + f' -profile {profile}'
if preset_combobox.get() == "Medium (Default)": preset = "medium"
else: preset = preset_combobox.get().lower()
ffmpeg_command = ffmpeg_command + f' -preset {preset}'
if tune_combobox.get() == "None (Default)":
pass
else:
tune = tune_combobox.get().lower().replace(" ", "")
ffmpeg_command = ffmpeg_command + f' -tune {tune}'
if video_crf_or_bitrate.get() == "crfr":
if crf_slider.get() == "23 (Default)": crf = "23"
elif crf_slider.get() == "0 (Loseless Quality)": crf = "0"
elif crf_slider.get() == "51 (Highest Quality)": crf = "51"
else: crf = crf_slider.get()
ffmpeg_command = ffmpeg_command + f' -crf {crf}'
else:
try:
if int(bitrate_entry.get()) not in range(100, 50001):
bitrate_entry.configure(border_color = "red")
return messagebox.showerror(title = "Wrong Video Bitrate", message = "Please select a valid video bitrate (from 100 to 50000).")
except ValueError:
bitrate_entry.configure(border_color = "red")
return messagebox.showerror(title = "Wrong Video Bitrate", message = "Please select a valid video bitrate (from 100 to 50000).")
else: fps = fps_combobox.get()
bitrate = bitrate_entry.get() + "K"
ffmpeg_command = ffmpeg_command + f' -b:v {bitrate}'
advanced_quality_settings = "video"
else:
advanced_quality_settings = "audio"
if aformat_combobox.get() == "MP3 (Default)":
format_codec = "libmp3lame"
advanced_extention = "mp3"
elif aformat_combobox.get() == "WAV":
format_codec = "pcm_s32le"
advanced_extention = "wav"
elif aformat_combobox.get() == "AAC":
format_codec = "aac"
advanced_extention = "aac"
elif aformat_combobox.get() == "OPUS":
format_codec = "libopus"
advanced_extention = "opus"
elif aformat_combobox.get() == "FLAC":
format_codec = "flac"
advanced_extention = "flac"
ffmpeg_command = ffmpeg_command + f' -c:a {format_codec}'
if audio_quality_or_bitrate.get() == "bitrate":
abitrate = abitrate_combobox.get() + "K"
ffmpeg_command = ffmpeg_command + f' -b:a {abitrate}'
else:
ffmpeg_command = ffmpeg_command + f' -q:a {aquality_combobox.get()}'
ffmpeg_command = ffmpeg_command + ' -progress pipe:1 "output"'
print(ffmpeg_command)
print(advanced_quality_settings)
print(advanced_extention)
advWindow.withdraw()
root.deiconify()
customtkinter.CTkLabel(root, text = "(Advanced Quality Settings will apply on your next downloads)", font = ("arial", 12)).place(x = 360 , y = 340)
# Placing the buttons
customtkinter.CTkButton(advWindow, text = "OK", font = ("arial bold", 20), width = 120, corner_radius = 20, command = okButton).place(x = 565 , y = 415)
customtkinter.CTkButton(advWindow, text = "Reset", font = ("arial bold", 20), width = 120, corner_radius = 20, command = resetButton).place(x = 435 , y = 415)
customtkinter.CTkButton(advWindow, text = "Cancel", font = ("arial bold", 20), width = 120, corner_radius = 20, command = cancelButton).place(x = 305 , y = 415)
root.withdraw()
advWindow.deiconify()
# Advanced Settings Window
def AboutWindow():
global abtWindow
def onClosing():
abtWindow.destroy()
root.deiconify()
try:
abtWindow.deiconify()
root.withdraw()
except:
# Form creating
abtWindow = customtkinter.CTkToplevel() # Toplevel object which will be treated as a new window
abtWindow.withdraw()
abtWindow.title("About Developer")
width = 700
height = 460
x = (abtWindow.winfo_screenwidth() // 2) - (width // 2)
y = (abtWindow.winfo_screenheight() // 2) - (height // 2)
abtWindow.geometry(fr"{width}x{height}+{x}+{y}")
abtWindow.maxsize(700, 460)
abtWindow.minsize(700, 460)
if platform == "linux" or platform == "linux2": pass
else:
try: abtWindow.iconbitmap("YDICO.ico") # Windows
except TclError: abtWindow.iconbitmap("_internal/YDICO.ico") # Windows
abtWindow.protocol("WM_DELETE_WINDOW", onClosing)
# Back to home button
back_button = customtkinter.CTkButton(abtWindow, text = "Back To Home", font = ("arial bold", 20), command = onClosing, corner_radius = 20)
back_button.place(x = 20 , y = 420)
# About info
customtkinter.CTkLabel(abtWindow, text = "Developer:", font = ("arial bold", 30)).place(x = 20 , y = 15)
customtkinter.CTkLabel(abtWindow, text = "Mohamed Ayman", font = ("arial bold", 25)).place(x = 185 , y = 20)
customtkinter.CTkLabel(abtWindow, text = "Email:", font = ("arial bold", 30)).place(x = 20 , y = 65)
customtkinter.CTkLabel(abtWindow, text = "[email protected]", font = ("arial bold", 25)).place(x = 117 , y = 70)
customtkinter.CTkLabel(abtWindow, text = "Github:", font = ("arial bold", 30)).place(x = 20 , y = 115)
github_label = customtkinter.CTkLabel(abtWindow, text = "github.com/mayman007", font = ("arial bold", 25), text_color="blue", cursor="hand2")
github_label.place(x = 137 , y = 120)
github_label.bind("<Button-1>", lambda e: webbrowser.open_new("http://github.com/mayman007"))
customtkinter.CTkLabel(abtWindow, text = "Website:", font = ("arial bold", 30)).place(x = 20 , y = 165)
website_label = customtkinter.CTkLabel(abtWindow, text = "mohamedayman.pages.dev", font = ("arial bold", 25), text_color="blue", cursor="hand2")
website_label.place(x = 152 , y = 170)
website_label.bind("<Button-1>", lambda e: webbrowser.open_new("http://mohamedayman.pages.dev"))
root.withdraw()
abtWindow.deiconify()
# Advanced settings button
advanced_quality_settings = "no"
adv_quailty_button = customtkinter.CTkButton(root, text = "Advanced Quality Settings", width = 175, font = ("arial bold", 15), command = AdvancedWindow, corner_radius = 20)
adv_quailty_button.place(x = 460 , y = 375)
# About button
about_button = customtkinter.CTkButton(root, text = "About Developer", width = 175, font = ("arial bold", 15), command = AboutWindow, corner_radius = 20)
about_button.place(x = 460 , y = 415)
# Conversion function
def Conversion(input, ext, seconds):
global ffmpeg_command
output = input.replace(fr").{ext}", fr"_advanced_settings_applied).{advanced_extention}")
ffmpeg_command = ffmpeg_command.replace("input", input)
ffmpeg_command = ffmpeg_command.replace("output", output)
# Progress reader function
def progress_reader(procs, q):
while True:
if procs.poll() is not None: break # Break if FFmpeg sun-process is closed
progress_text = procs.stdout.readline() # Read line from the pipe
# Break the loop if progress_text is None (when pipe is closed).
if progress_text is None: break
progress_text = progress_text.decode("utf-8") # Convert bytes array to strings
# Look for "frame=xx"
if progress_text.startswith("frame="):
frame = int(progress_text.partition('=')[-1]) # Get the frame number
q[0] = frame # Store the last sample
# Count number of frames
tot_n_frames = seconds * float(fps)
# Execute FFmpeg as sub-process with stdout as a pipe
# Redirect progress to stdout using -progress pipe:1 arguments
process = subprocess.Popen(shlex.split(ffmpeg_command), stdout=subprocess.PIPE)
q = [0] # We don't really need to use a Queue - use a list of size 1
progress_reader_thread = Thread(target=progress_reader, args=(process, q)) # Initialize progress reader thread
progress_reader_thread.start() # Start the thread
while True:
if process.poll() is not None: break # Break if FFmpeg sun-process is closed
time.sleep(1) # Sleep 1 second (do some work...)
n_frame = q[0] # Read last element from progress_reader - current encoded frame
progress_percent = (n_frame/tot_n_frames)*100 # Convert to percentage.
print(f'Progress [%]: {progress_percent:.2f} ') # Print the progress
if ext == "mp4": converting_percentage_var.set(f'{progress_percent:.2f}%') # Show the progress
else: pass # For some reson, progress doesn't get printed when it's an audio
process.stdout.close() # Close stdin pipe.
progress_reader_thread.join() # Join thread
process.wait() # Wait for FFmpeg sub-process to finish
ffmpeg_command = ffmpeg_command.replace(input, "input")
ffmpeg_command = ffmpeg_command.replace(output, "output")
# Download window
def DownlaodWindow():
# Starting
def VideoStart():
threading.Thread(target = Downloading, args = (downloading_var,)).start()
threading.Thread(target = VideoDownloader).start()
# Back home
def backHome():
download = downloading_var.get()
non_downloading_list = ["", "Finished", "Canceled"]
if download in non_downloading_list:
pass
else:
msg_box = messagebox.askquestion(title = "Cancel Download",
message = "Going back to home will cancel the current download.\n\nDo you wish to continue?",
icon = "warning")
if msg_box == "yes": pass
else: return
newWindow.destroy()
root.deiconify()
# Set path
if platform == "linux" or platform == "linux2": path = fr"/home/{os.getlogin()}/Downloads"
else: path = fr"C:/Users\{os.getlogin()}\Downloads"
global directory
directory = os.path.realpath(path) # Deafult path in case the user didn't choose
def BrowseDir(): # Path function
global directory2
directory2 = filedialog.askdirectory()
path_var.set(directory2)
# When an error happens
def whenVideoError():
toggle_button = customtkinter.CTkButton(newWindow, text = "⏸️", font = ("arial", 15), fg_color = "grey14", text_color = "CadetBlue1", width = 5, height = 26, state = "disabled")
toggle_button.place(x = 550 , y = 347)
cancel_button = customtkinter.CTkButton(newWindow, text = "Cancel", font = ("arial bold", 12), fg_color = "red2", width = 80, height = 26, state = "disabled", corner_radius = 20)
cancel_button.place(x = 595 , y = 347)
download_button = customtkinter.CTkButton(newWindow, text = "Download", font = ("arial bold", 25), command = VideoStart)
download_button.place(x = 540 , y = 306)
path_button = customtkinter.CTkButton(newWindow, text = "Change Path", font = ("arial bold", 12), fg_color = "dim grey", hover_color = "gray25", width = 5, command = BrowseDir, corner_radius = 20)
path_button.place(x = 430 , y = 347)
lang_choose.configure(state = "normal")
try: adv_checkbox.configure(state = "normal")
except: pass
downloading_var.set(" ")
progress_label.configure(text_color = "#DCE4EE")
progress_size_label.configure(text_color = "#DCE4EE")
# Captions download
def CaptionsDownload():
lang = lang_choose.get()
if lang.lower() == "none":
return
elif lang.lower() == "arabic":
lang = "ar"
elif lang.lower() == "english":
for transcript in transcript_list:
if transcript.language_code == "en-US":
lang = "en-US"
break
elif transcript.language_code == "en-UK":
lang = "en-UK"
break
else:
lang = "en"
try: # Get the subtitle directly if it's there
final = YouTubeTranscriptApi.get_transcript(video_id = video_id, languages = [lang])
print("got one already there")
sub = "subtitle"
except: # If not then translate it
translated = "no"
en_list = ["en", "en-US","en-UK"]
for transcript in transcript_list:
if transcript.language_code in en_list: # Translate from English if it's there
final = transcript.translate(lang).fetch()
print(fr"translated from {transcript.language_code}")
sub = "translated_subtitle"
translated = "yes"
if translated == "no": # Avoid translating twice
final = transcript.translate(lang).fetch()
print(fr"translated {transcript.language_code}")
sub = "translated_subtitle"
translated = "yes"
else:
pass
formatter = SRTFormatter()
srt_formatted = formatter.format_transcript(final)
try:
with open(fr"{directory2}/{clean_filename(url.title)}_{sub}_{lang}.srt", "w", encoding = "utf-8") as srt_file:
srt_file.write(srt_formatted)
except NameError:
with open(fr"{directory}/{clean_filename(url.title)}_{sub}_{lang}.srt", "w", encoding = "utf-8") as srt_file:
srt_file.write(srt_formatted)
# Advanced checker
def advancedChecker():
global advanced_quality_settings
if advanced_quality_settings == "no": advanced_quality_settings = "yes"
elif advanced_quality_settings == "yes": advanced_quality_settings = "no"
# Pause/Resume function
def toggle_download():
global is_paused
is_paused = not is_paused
if is_paused:
toggle_button = customtkinter.CTkButton(newWindow, text = "▶️", font = ("arial", 15), fg_color = "grey14", hover_color = "gray10", text_color = "CadetBlue1", width = 5, height = 26, command = toggle_download)
toggle_button.place(x = 550 , y = 347)
downloading_var.set("Paused")
else:
toggle_button = customtkinter.CTkButton(newWindow, text = "⏸️", font = ("arial", 15), fg_color = "grey14", hover_color = "gray10", text_color = "CadetBlue1", width = 5, height = 26, command = toggle_download)
toggle_button.place(x = 550 , y = 347)
downloading_var.set("Downloading")
# Cancel function
def cancel_download():
global is_cancelled
is_cancelled = True
# Open folder in file explorer when download is finished
def openFile():
try:
try:
dir2 = os.path.normpath(directory2)
if platform == "linux" or platform == "linux2": subprocess.Popen(dir2)
else: subprocess.Popen(f'explorer "{dir2}"')
except NameError:
if platform == "linux" or platform == "linux2": subprocess.Popen(directory)
else: subprocess.Popen(f'explorer "{directory}"')
except PermissionError:
try: messagebox.showerror(title = "Permission Denied", message = fr"I do not have permission to open '{dir2}'")
except NameError: messagebox.showerror(title = "Permission Denied", message = fr"I do not have permission to open '{directory}'")
# One Video Downloader
def VideoDownloader(event = None):
# Preperations
global is_paused, is_cancelled
toggle_button = customtkinter.CTkButton(newWindow, text = "⏸️", font = ("arial", 15), fg_color = "grey14", hover_color = "gray10", text_color = "CadetBlue1", width = 5, height = 26, command = toggle_download)
toggle_button.place(x = 550 , y = 347)
cancel_button = customtkinter.CTkButton(newWindow, text = "Cancel", font = ("arial bold", 12), fg_color = "red2", hover_color = "red4", width = 80, height = 26, command = cancel_download, corner_radius = 20)
cancel_button.place(x = 595 , y = 347)
download_button = customtkinter.CTkButton(newWindow, text = "Download", font = ("arial bold", 25), state = "disabled", corner_radius = 20)
download_button.place(x = 540 , y = 306)
path_button = customtkinter.CTkButton(newWindow, text = "Change Path", font = ("arial bold", 12), fg_color = "dim grey", width = 5, state = "disabled", corner_radius = 20)
path_button.place(x = 430 , y = 347)
lang_choose.configure(state = "disabled")
try: adv_checkbox.configure(state = "disabled")
except: pass
audio_tags_list = ["251" , "140" , "250" , "249"]
non_progressive_list = ["137" , "22", "135" , "133", "160"]
# Download subtitles if selected
if caps == "yes": CaptionsDownload()
else: pass
# Progress stuff
pytubefix.request.default_range_size = 2097152 # 2MB chunk size (update progress every 2MB)
progress_label.configure(text_color = "green")
progress_size_label.configure(text_color = "LightBlue")
# If the quality is non progressive video (1080p, 480p, 240p and 144p)
if quality in non_progressive_list:
if quality == "137": video = url.streams.filter(res = "1080p").first()
elif quality == "22": video = url.streams.filter(res = "720p").first()
elif quality == "135": video = url.streams.filter(res = "480p").first()
elif quality == "133": video = url.streams.filter(res = "240p").first()
elif quality == "160": video = url.streams.filter(res = "144p").first()
audio = url.streams.get_by_itag(251)
size = video.filesize + audio.filesize
try:
vname = fr"{directory2}/{clean_filename(url.title)}_video.mp4"
aname = fr"{directory2}/{clean_filename(url.title)}_audio.mp3"
except NameError:
vname = fr"{directory}/{clean_filename(url.title)}_video.mp4"
aname = fr"{directory}/{clean_filename(url.title)}_audio.mp3"
# Downlaod video
try:
with open(vname, "wb") as f:
is_paused = is_cancelled = False
video = request.stream(video.url) # Get an iterable stream
downloaded = 0
while True:
if is_cancelled:
downloading_var.set("Canceled")
break
if is_paused:
time.sleep(0.1)