-
Notifications
You must be signed in to change notification settings - Fork 5
/
Mp4-Mux-Tool.py
2365 lines (2114 loc) · 90.8 KB
/
Mp4-Mux-Tool.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 pathlib
import platform
import pyperclip
import subprocess
import threading
import tkinter as tk
import tkinter.scrolledtext as scrolledtextwidget
import webbrowser
from tkinter import (
filedialog,
StringVar,
ttk,
messagebox,
PhotoImage,
Menu,
LabelFrame,
E,
N,
S,
W,
Label,
Entry,
DISABLED,
NORMAL,
END,
Frame,
Spinbox,
CENTER,
Checkbutton,
HORIZONTAL,
Toplevel,
SUNKEN,
OptionMenu,
Button,
)
from tkinterdnd2 import TkinterDnD, DND_FILES
from pymediainfo import MediaInfo
from ISO_639_2 import *
from packages.about import openaboutwindow
from packages.chapterdemuxer import ChapterDemux
from packages.base64images import icon_image
from packages.configparams import *
from packages.dpi_scaling import enable_dpi_scaling
# Main Gui & Windows --------------------------------------------------------------------------------------------------
def mp4_root_exit_function(): # Pop up window when you file + exit or press 'X' to close the program
confirm_exit = messagebox.askyesno(
title="Prompt",
message="Are you sure you want to exit the program?\n\n"
" Note: This will end all current tasks!",
parent=mp4_root,
)
if (
confirm_exit
): # If user selects 'Yes', program attempts to kill all tasks then closes GUI
try:
subprocess.Popen(
f"TASKKILL /F /im MP4-Mux-Tool.exe /T",
creationflags=subprocess.CREATE_NO_WINDOW,
)
mp4_root.destroy()
except (Exception,):
mp4_root.destroy()
mp4_root = TkinterDnD.Tk() # Main loop with DnD.Tk() module (for drag and drop)
mp4_root.title("MP4-Mux-Tool v1.21") # Sets the version of the program
mp4_root.iconphoto(True, PhotoImage(data=icon_image)) # Sets icon for all windows
mp4_root.configure(background="#434547") # Sets gui background color
window_height = 750 # Gui window height
window_width = 700 # Gui window width
screen_width = mp4_root.winfo_screenwidth() # down
screen_height = mp4_root.winfo_screenheight() # down
x_coordinate = int((screen_width / 2) - (window_width / 2)) # down
y_coordinate = int((screen_height / 2) - (window_height / 2)) # down
mp4_root.geometry(
f"{window_width}x{window_height}+{x_coordinate}+{y_coordinate}"
) # does the math for center open
mp4_root.protocol(
"WM_DELETE_WINDOW", mp4_root_exit_function
) # Code to use exit function when selecting 'X'
if platform.system() == "Windows":
enable_dpi_scaling()
# mp4_root Row/Column Configure ---------------------------------------------------------------------------------------
for n in range(3):
mp4_root.grid_columnconfigure(n, weight=1)
for n in range(6):
mp4_root.grid_rowconfigure(n, weight=1)
# --------------------------------------------------------------------------------------- mp4_root Row/Column Configure
# Menu Items and Sub-Bars ---------------------------------------------------------------------------------------------
my_menu_bar = Menu(mp4_root, tearoff=0)
mp4_root.config(menu=my_menu_bar)
file_menu = Menu(my_menu_bar, tearoff=0, activebackground="dim grey")
my_menu_bar.add_cascade(label="File", menu=file_menu)
def clear_inputs(): # Clears/Resets the entire GUI/variables to "default" or None
global VideoInput, video_title_cmd_input, video_title_entrybox, video_combo_language, input_entry, audio_input, audio_title_cmd, audio_title_entrybox, audio_delay, audio_input_entry, subtitle_input, subtitle_input_entry, subtitle_language, subtitle_title_cmd_input, subtitle_title_entrybox, chapter_input, chapter_input_entry, chapter_title_cmd_input, output, output_entry
try: # Video Reset
video_title_cmd_input = ""
video_title_entrybox.configure(state=NORMAL)
video_title_entrybox.delete(0, END)
video_title_entrybox.configure(state=DISABLED)
video_combo_language.current(0)
input_entry.configure(state=NORMAL)
input_entry.delete(0, END)
input_entry.configure(state=DISABLED)
status_label.configure(
text='Select "Open File" or drag and drop a video file to begin'
)
show_command.configure(state=DISABLED)
start_button.configure(state=DISABLED)
del VideoInput
except NameError as v:
v_error = str(v)
try: # Audio Reset
audio_title_cmd = ""
audio_title_entrybox.delete(0, END)
audio_title_entrybox.configure(state=DISABLED)
audio_input_entry.configure(state=NORMAL)
audio_input_entry.delete(0, END)
audio_input_entry.configure(state=DISABLED)
audio_language.current(0)
audio_delay.set(0)
audio_input_button.configure(state=DISABLED)
del audio_input
except NameError as a1:
a1_error = str(a1)
try: # Subtitle Reset
subtitle_title_cmd_input = ""
subtitle_input_entry.configure(state=NORMAL)
subtitle_input_entry.delete(0, END)
subtitle_input_entry.configure(state=DISABLED)
subtitle_title_entrybox.configure(state=NORMAL)
subtitle_title_entrybox.delete(0, END)
subtitle_title_entrybox.configure(state=DISABLED)
subtitle_language.current(0)
subtitle_input_button.configure(state=DISABLED)
del subtitle_input
except NameError as s1:
s1_error = str(s1)
try: # Chapter Reset
chapter_title_cmd_input = ""
chapter_input_entry.configure(state=NORMAL)
chapter_input_entry.delete(0, END)
chapter_input_entry.configure(state=DISABLED)
chapter_input_button.configure(state=DISABLED)
del chapter_input
except NameError as c:
c_error = str(c)
try: # Output Reset
output_entry.configure(state=NORMAL)
output_entry.delete(0, END)
output_entry.configure(state=DISABLED)
output_button.configure(state=DISABLED)
del output
except NameError as o:
o_error = str(o)
file_menu.add_command(label="Clear Inputs", command=clear_inputs)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=mp4_root_exit_function)
options_menu = Menu(my_menu_bar, tearoff=0, activebackground="dim grey")
my_menu_bar.add_cascade(label="Options", menu=options_menu)
options_submenu = Menu(mp4_root, tearoff=0, activebackground="dim grey")
options_menu.add_cascade(label="Shell Options", menu=options_submenu)
shell_options = StringVar()
shell_options.set(config["debug_option"]["option"])
if shell_options.get() == "":
shell_options.set("Default")
elif shell_options.get() != "":
shell_options.set(config["debug_option"]["option"])
def update_shell_option():
try:
config.set("debug_option", "option", shell_options.get())
with open(config_file, "w") as configfile:
config.write(configfile)
except (Exception,):
pass
update_shell_option()
options_submenu.add_radiobutton(
label="Progress Bars",
variable=shell_options,
value="Default",
command=update_shell_option,
)
options_submenu.add_radiobutton(
label="CMD Shell (Debug)",
variable=shell_options,
value="Debug",
command=update_shell_option,
)
auto_close_window = StringVar()
auto_close_window.set(config["auto_close_progress_window"]["option"])
if auto_close_window.get() == "":
auto_close_window.set("on")
elif auto_close_window.get() != "":
auto_close_window.set(config["auto_close_progress_window"]["option"])
def update_auto_close():
try:
config.set("auto_close_progress_window", "option", auto_close_window.get())
with open(config_file, "w") as configfile:
config.write(configfile)
except (Exception,):
pass
update_auto_close()
options_submenu2 = Menu(mp4_root, tearoff=0, activebackground="dim grey")
options_menu.add_cascade(
label="Auto-Close Progress Window On Completion", menu=options_submenu2
)
options_submenu2.add_radiobutton(
label="On", variable=auto_close_window, value="on", command=update_auto_close
)
options_submenu2.add_radiobutton(
label="Off", variable=auto_close_window, value="off", command=update_auto_close
)
reset_gui_on_start = StringVar()
reset_gui_on_start.set(config["reset_program_on_start_job"]["option"])
if reset_gui_on_start.get() == "":
reset_gui_on_start.set("on")
elif reset_gui_on_start.get() != "":
reset_gui_on_start.set(config["reset_program_on_start_job"]["option"])
def update_reset_on_job():
try:
config.set("reset_program_on_start_job", "option", reset_gui_on_start.get())
with open(config_file, "w") as configfile:
config.write(configfile)
except (Exception,):
pass
update_reset_on_job()
options_submenu3 = Menu(mp4_root, tearoff=0, activebackground="dim grey")
options_menu.add_cascade(
label="Reset GUI When Start Job Is Selected", menu=options_submenu3
)
options_submenu3.add_radiobutton(
label="On", variable=reset_gui_on_start, value="on", command=update_reset_on_job
)
options_submenu3.add_radiobutton(
label="Off", variable=reset_gui_on_start, value="off", command=update_reset_on_job
)
options_menu.add_separator()
def set_mp4box_path():
global mp4box
path = filedialog.askopenfilename(
title='Select Location to "mp4box.exe"',
initialdir="/",
filetypes=[("MP4Box", "mp4box.exe")],
)
if path != "":
mp4box = '"' + str(pathlib.Path(path)) + '"'
config.set("mp4box_path", "path", mp4box)
with open(config_file, "w") as configfile:
config.write(configfile)
options_menu.add_command(label="Set path to MP4Box", command=set_mp4box_path)
def set_mkvextract_path():
global mp4box
path = filedialog.askopenfilename(
title='Select Location to "mkvextract.exe"',
initialdir="/",
filetypes=[("mkvextract", "mkvextract.exe")],
)
if path != "":
mkvextract = '"' + str(pathlib.Path(path)) + '"'
config.set("mkvextract_path", "path", mkvextract)
with open(config_file, "w") as configfile:
config.write(configfile)
options_menu.add_command(label="Set path to mkvextract", command=set_mkvextract_path)
options_menu.add_separator()
def reset_config():
msg = messagebox.askyesno(
title="Warning",
message="Are you sure you want to reset the config.ini file settings?",
)
if msg:
try:
config.set("mp4box_path", "path", "")
config.set("mkvextract_path", "path", "")
config.set("debug_option", "option", "")
config.set("auto_close_progress_window", "option", "")
config.set("reset_program_on_start_job", "option", "")
with open(config_file, "w") as configfile:
config.write(configfile)
messagebox.showinfo(title="Prompt", message="Please restart the program")
subprocess.Popen(
f"TASKKILL /F /im MP4-Mux-Tool.exe /T",
creationflags=subprocess.CREATE_NO_WINDOW,
)
except (Exception,):
mp4_root.destroy()
mp4_root.destroy()
options_menu.add_command(label="Reset Configuration File", command=reset_config)
tools_menu = Menu(my_menu_bar, tearoff=0, activebackground="dim grey")
my_menu_bar.add_cascade(label="Tools", menu=tools_menu)
tools_menu.add_command(
label="Chapter Demuxer",
command=lambda: ChapterDemux(master=mp4_root, standalone=False),
)
help_menu = Menu(my_menu_bar, tearoff=0, activebackground="dim grey")
my_menu_bar.add_cascade(label="Help", menu=help_menu)
help_menu.add_command(label="About", command=openaboutwindow)
# --------------------------------------------------------------------------------------------- Menu Items and Sub-Bars
# Themes --------------------------------------------------------------------------------------------------------------
# Custom Tkinter Theme-----------------------------------------
custom_style = ttk.Style()
custom_style.theme_create(
"jlw_style",
parent="alt",
settings={
# Notebook Theme Settings -------------------
"TNotebook": {"configure": {"tabmargins": [5, 5, 5, 0]}},
"TNotebook.Tab": {
"configure": {
"padding": [5, 1],
"background": "grey",
"foreground": "white",
"focuscolor": "",
},
"map": {
"background": [("selected", "#434547")],
"expand": [("selected", [1, 1, 1, 0])],
},
},
# Notebook Theme Settings -------------------
# ComboBox Theme Settings -------------------
"TCombobox": {
"configure": {
"selectbackground": "#23272A",
"fieldbackground": "#23272A",
"background": "white",
"foreground": "white",
}
},
}
# ComboBox Theme Settings -------------------
)
custom_style.theme_use("jlw_style") # Enable the use of the custom theme
# ComboBox Mouse Hover Code ----------------------------------
mp4_root.option_add("*TCombobox*Listbox*Background", "#404040")
mp4_root.option_add("*TCombobox*Listbox*Foreground", "#FFFFFF")
mp4_root.option_add("*TCombobox*Listbox*selectBackground", "#FFFFFF")
mp4_root.option_add("*TCombobox*Listbox*selectForeground", "#404040")
custom_style.map(
"TCombobox", foreground=[("hover", "white")], background=[("hover", "grey")]
)
custom_style.configure("purple.Horizontal.TProgressbar", background="purple")
# -------------------------------------------------------------------------------------------------------------- Themes
class HoverButton(Button):
"""simple class to convert button to a hoverbutton"""
def __init__(self, master, **kw):
Button.__init__(self, master=master, **kw)
self.defaultBackground = self["background"]
self.bind("<Enter>", self.on_enter)
self.bind("<Leave>", self.on_leave)
def on_enter(self, e):
self["background"] = self["activebackground"]
if self.cget("text") == "Video":
status_label.configure(
text="Video inputs supported (.avc, .avi, .mp4, .m1v/.m2v, .m4v, .264, .h264, .hevc, or "
".h265)"
)
if self.cget("text") == "Audio":
status_label.configure(
text="Audio inputs supported (.ac3, .aac, .mp4, .m4a, .mp2, .mp3, .opus, .ogg, or .eac3)"
)
if self.cget("text") == "Subtitle":
status_label.configure(text="Subtitle inputs supported (.srt, .idx, .ttxt)")
if self.cget("text") == "Chapter":
status_label.configure(text="Chapter input supported OGG (.txt)")
if self.cget("text") == "Output":
status_label.configure(text="Select File Save Location (*.mp4)")
if self.cget("text") == "X":
status_label.configure(text="Remove input and settings")
if self.cget("text") == "View Command":
status_label.configure(text="Select to show complete command line")
if self.cget("text") == "Mux":
status_label.configure(text="Select to begin muxing")
def on_leave(self, e):
self["background"] = self.defaultBackground
status_label.configure(text="")
# Bundled apps --------------------------------------------------------------------------------------------------------
mp4box = config["mp4box_path"]["path"]
if not pathlib.Path(
mp4box.replace('"', "")
).is_file(): # Checks config for bundled app paths path
# mp4box -----------------------------------------------------------------------
if pathlib.Path(
"apps/mp4box/MP4Box.exe"
).is_file(): # If mp4box.exe is located in the apps folder
messagebox.showinfo(
title="Info",
message="Program will use the included "
'"mp4box.exe" located in the "apps" folder',
)
mp4box = (
'"' + str(pathlib.Path("apps/mp4box/MP4Box.exe")) + '"'
) # sets variable to mp4box.exe
try: # Write path location to config.ini file
config.set("mp4box_path", "path", mp4box)
with open(config_file, "w") as configfile:
config.write(configfile)
except (
Exception,
): # If unable to write path to mp4box.exe present error message
messagebox.showerror(
title="Error!",
message=f"Could not save path to mp4box at "
f"\n{mp4box}\n please try again",
)
elif not pathlib.Path(
"apps/mp4box/MP4Box.exe"
).is_file(): # If mp4box.exe does not exist
messagebox.showerror(
title="Error!",
message="Please download mp4box.exe and set path to "
"mp4box.exe in the Options menu",
) # Error message
webbrowser.open(
"https://www.mediafire.com/file/8pymy2869rmy5x5/mp4box.zip/file"
) # Gets recent build
# mp4box ------------------------------------------------------------------------
mkvextract = config["mkvextract_path"]["path"]
if not pathlib.Path(
mkvextract.replace('"', "")
).is_file(): # Checks config for bundled app paths path
# mkvextract -----------------------------------------------------------------------
if pathlib.Path(
"apps/mkvextract/mkvextract.exe"
).is_file(): # If mkvextract.exe is located in the apps folder
messagebox.showinfo(
title="Info",
message="Program will use the included "
'"mkvextract.exe" located in the "apps" folder',
)
mkvextract = (
'"' + str(pathlib.Path("apps/mkvextract/mkvextract.exe")) + '"'
) # sets variable to mkvextract.exe
try: # Write path location to config.ini file
config.set("mkvextract_path", "path", mkvextract)
with open(config_file, "w") as configfile:
config.write(configfile)
except (
Exception,
): # If unable to write path to mp4box.exe present error message
messagebox.showerror(
title="Error!",
message=f"Could not save path to mkvextract at "
f"\n{mkvextract}\n please try again",
)
elif not pathlib.Path(
"apps/mkvextract/mkvextract.exe"
).is_file(): # If mkvextract.exe does not exist
messagebox.showerror(
title="Error!",
message="Please download mkvextract.exe and set path to "
"mkvextract.exe in the Options menu",
) # Error message
webbrowser.open(
"https://www.fosshub.com/MKVToolNix.html?dwl=mkvtoolnix-64-bit-64.0.0.7z"
)
# Opens default web-browser to mkvextract (mkvtoolnix)
# mkvextract ------------------------------------------------------------------------
# -------------------------------------------------------------------------------------------------------- Bundled apps
# Video Frame ---------------------------------------------------------------------------------------------------------
video_frame = LabelFrame(mp4_root, text=" Video ")
video_frame.grid(row=0, columnspan=3, sticky=E + W + N + S, padx=20, pady=(5, 0))
video_frame.configure(fg="white", bg="#434547", bd=4)
video_frame.grid_columnconfigure(0, weight=1)
video_frame.grid_rowconfigure(0, weight=1)
# Video Notebook Frame ------------------------------------------------------------------------------------------------
tabs = ttk.Notebook(video_frame, height=110)
tabs.grid(row=0, column=0, columnspan=4, sticky=E + W + N + S, padx=10, pady=5)
video_tab = Frame(tabs, background="#434547")
tabs.add(video_tab, text=" Input ")
for n in range(4):
video_tab.grid_columnconfigure(n, weight=1)
video_tab.grid_columnconfigure(0, weight=1, minsize=120)
video_tab.grid_columnconfigure(1, weight=100)
for n in range(3):
video_tab.grid_rowconfigure(n, weight=1)
# ------------------------------------------------------------------------------------------------ Video Notebook Frame
# Entry Box for Video Title -------------------------------------------------------------------------------------------
def video_title(*args):
global video_title_cmd_input
if (
video_title_cmd.get().strip() == ""
): # If title box string is empty or only white space
video_title_cmd_input = ":name=" # .strip() is used to remove all white space from left or right of a string
else: # If title box string has characters
video_title_cmd_input = ":name=" + video_title_cmd.get().strip()
video_title_cmd = StringVar()
video_title_entrybox_label = Label(
video_tab, text="Video Title:", anchor=W, background="#434547", foreground="white"
)
video_title_entrybox_label.grid(
row=1, column=1, columnspan=1, padx=10, pady=(0, 0), sticky=W
)
video_title_entrybox = Entry(
video_tab,
textvariable=video_title_cmd,
borderwidth=4,
background="#CACACA",
state=DISABLED,
)
video_title_entrybox.grid(
row=2, column=1, columnspan=3, padx=(5, 15), pady=(0, 15), sticky=W + E
)
video_title_cmd.trace("w", video_title)
video_title_cmd.set("")
# ---------------------------------------------------------------------------------------------------- Video Title Line
# Video Language Selection --------------------------------------------------------------------------------------------
video_language = StringVar()
video_language_menu_label = Label(
video_tab, text="Language:", background="#434547", foreground="white"
)
video_language_menu_label.grid(
row=1, column=0, columnspan=1, padx=10, pady=(0, 0), sticky=W
)
video_combo_language = ttk.Combobox(
video_tab,
values=list(iso_639_2_codes_dictionary.keys()),
justify="center",
textvariable=video_language,
width=15,
)
video_combo_language.grid(
row=2, column=0, columnspan=1, padx=10, pady=(0, 10), sticky=W + E + N + S
)
video_combo_language["state"] = "readonly"
video_combo_language.current(0) # Sets language to index 0 (UND) by default
# ------------------------------------------------------------------------------------------------------ Video Language
def input_button_commands(): # Open file block of code (non drag and drop)
global VideoInput, autosavefilename, autofilesave_dir_path, VideoInputQuoted, output, output_quoted, chapter_input
video_extensions = (
".avi",
".mp4",
".m1v",
".m2v",
".m4v",
".264",
".h264",
".hevc",
".h265",
".avc",
)
VideoInput = filedialog.askopenfilename(
initialdir="/",
title="Select A File",
filetypes=[("Supported Formats", video_extensions)],
)
if VideoInput:
input_entry.configure(state=NORMAL)
input_entry.delete(0, END)
if VideoInput.endswith(video_extensions):
autofilesave_file_path = pathlib.Path(
VideoInput
) # Command to get file input location
autofilesave_dir_path = autofilesave_file_path.parents[
0
] # Final command to get only the directory
VideoInputQuoted = '"' + str(pathlib.Path(VideoInput)) + '"'
input_entry.insert(0, str(pathlib.Path(VideoInput)))
filename = pathlib.Path(VideoInput)
VideoOut = filename.with_suffix("")
autosavefilename = str(VideoOut.name) + ".muxed_output"
autosave_file_dir = pathlib.Path(
str(f"{autofilesave_dir_path}\\") + str(autosavefilename + ".mp4")
)
output = str(autosave_file_dir)
output_quoted = '"' + output + '"'
input_entry.configure(state=DISABLED)
video_title_entrybox.configure(state=NORMAL)
output_entry.configure(state=NORMAL)
output_entry.delete(0, END)
output_entry.configure(state=DISABLED)
output_entry.configure(state=NORMAL)
output_entry.insert(0, str(autosave_file_dir))
output_entry.configure(state=DISABLED)
output_button.configure(state=NORMAL)
audio_input_button.configure(state=NORMAL)
subtitle_input_button.configure(state=NORMAL)
chapter_input_button.configure(state=NORMAL)
output_button.configure(state=NORMAL)
start_button.configure(state=NORMAL)
show_command.configure(state=NORMAL)
media_info = MediaInfo.parse(filename)
for (
track
) in (
media_info.tracks
): # Use mediainfo module to parse video section to collect frame rate
if track.track_type == "Video":
try: # Code to detect the position of the language code, for 3 digit, and set it to a variable
detect_index = [len(i) for i in track.other_language].index(3)
language_index = list(
iso_639_2_codes_dictionary.values()
).index(track.other_language[detect_index])
video_combo_language.current(language_index)
video_title_entrybox.delete(0, END)
video_title_entrybox.insert(0, track.title)
except (Exception,):
pass
if (
config["auto_chapter_import"]["option"] == "on"
): # If checkbox to auto import chapter is checked
if track.track_type == "General":
if (
track.count_of_menu_streams is not None
): # If source has chapters continue code
finalcommand = (
'"'
+ mp4box
+ " "
+ f'"{filename}"'
+ " -dump-chap-ogg -out "
+ f'"{pathlib.Path(filename).with_suffix(".txt")}"'
+ '"'
)
# Use subprocess.run to execute, then wait to finish executing before code moves to next
subprocess.run(
"cmd /c " + finalcommand,
universal_newlines=True,
creationflags=subprocess.CREATE_NO_WINDOW,
)
if pathlib.Path(filename).with_suffix(".txt").is_file():
chapter_input_entry.configure(state=NORMAL)
chapter_input_entry.delete(0, END)
chapter_input_entry.insert(
0, f'Imported chapters from: "{filename.name}"'
)
chapter_input_entry.configure(state=DISABLED)
chapter_input = str(
pathlib.Path(filename).with_suffix(".txt")
)
else:
messagebox.showinfo(
title="Input Not Supported", # Error message if input is not a supported file type
message="Try Again With a Supported File Type!\n\nIf this is a "
"file that should be supported, please let me know.\n\n"
+ 'Unsupported file extension "'
+ str(pathlib.Path(VideoInput).suffix)
+ '"',
)
video_combo_language.current(0)
video_title_entrybox.delete(0, END)
del VideoInput
# ---------------------------------------------------------------------------------------------- Input Functions Button
# Drag and Drop Functions ---------------------------------------------------------------------------------------------
def video_drop_input(event): # Drag and drop function
input_dnd.set(event.data)
def update_file_input(*args): # Drag and drop block of code
global VideoInput, autofilesave_dir_path, VideoInputQuoted, output, autosavefilename, output_quoted, chapter_input
input_entry.configure(state=NORMAL)
input_entry.delete(0, END)
VideoInput = str(input_dnd.get()).replace("{", "").replace("}", "")
video_extensions = (
".avi",
".mp4",
".m1v",
".m2v",
".m4v",
".264",
".h264",
".hevc",
".h265",
)
if VideoInput.endswith(video_extensions):
autofilesave_file_path = pathlib.Path(
VideoInput
) # Command to get file input location
autofilesave_dir_path = autofilesave_file_path.parents[
0
] # Final command to get only the directory
VideoInputQuoted = '"' + str(pathlib.Path(VideoInput)) + '"'
input_entry.insert(0, str(input_dnd.get()).replace("{", "").replace("}", ""))
filename = pathlib.Path(VideoInput)
VideoOut = filename.with_suffix("")
autosavefilename = str(VideoOut.name) + ".muxed_output"
autosave_file_dir = pathlib.Path(
str(f"{autofilesave_dir_path}\\") + str(autosavefilename + ".mp4")
)
output = str(autosave_file_dir)
output_quoted = '"' + output + '"'
input_entry.configure(state=DISABLED)
video_title_entrybox.configure(state=NORMAL)
output_entry.configure(state=NORMAL)
output_entry.delete(0, END)
output_entry.configure(state=DISABLED)
output_entry.configure(state=NORMAL)
output_entry.insert(0, str(autosave_file_dir))
output_entry.configure(state=DISABLED)
output_button.configure(state=NORMAL)
audio_input_button.configure(state=NORMAL)
subtitle_input_button.configure(state=NORMAL)
chapter_input_button.configure(state=NORMAL)
output_button.configure(state=NORMAL)
start_button.configure(state=NORMAL)
show_command.configure(state=NORMAL)
media_info = MediaInfo.parse(filename)
for track in media_info.tracks:
if track.track_type == "Video":
try:
detect_index = [len(i) for i in track.other_language].index(3)
language_index = list(iso_639_2_codes_dictionary.values()).index(
track.other_language[detect_index]
)
video_combo_language.current(language_index)
video_title_entrybox.delete(0, END)
video_title_entrybox.insert(0, track.title)
except (Exception,):
pass
if (
config["auto_chapter_import"]["option"] == "on"
): # If checkbox to auto import chapter is checked
if track.track_type == "General":
if (
track.count_of_menu_streams is not None
): # If source has chapters continue code
finalcommand = (
'"'
+ mp4box
+ " "
+ f'"{filename}"'
+ " -dump-chap-ogg -out "
+ f'"{pathlib.Path(filename).with_suffix(".txt")}"'
+ '"'
)
# Use subprocess.run to execute, then wait to finish executing before code moves to next
subprocess.run(
"cmd /c " + finalcommand,
universal_newlines=True,
creationflags=subprocess.CREATE_NO_WINDOW,
)
if pathlib.Path(filename).with_suffix(".txt").is_file():
chapter_input_entry.configure(state=NORMAL)
chapter_input_entry.delete(0, END)
chapter_input_entry.insert(
0, f'Imported chapters from: "{filename.name}"'
)
chapter_input_entry.configure(state=DISABLED)
chapter_input = str(
pathlib.Path(filename).with_suffix(".txt")
)
else:
messagebox.showinfo(
title="Input Not Supported",
message="Try Again With a Supported File Type!\n\nIf this is a "
"file that should be supported, please let me know.\n\n"
+ 'Unsupported file extension "'
+ str(pathlib.Path(VideoInput).suffix)
+ '"',
)
video_combo_language.current(0)
video_title_entrybox.delete(0, END)
del VideoInput
# --------------------------------------------------------------------------------------------- Drag and Drop Functions
# Buttons -------------------------------------------------------------------------------------------------------------
input_dnd = StringVar()
input_dnd.trace("w", update_file_input)
input_button = HoverButton(
video_tab,
text="Video",
command=input_button_commands,
foreground="white",
background="#23272A",
borderwidth="3",
activebackground="grey",
width=15,
)
input_button.grid(row=0, column=0, columnspan=1, padx=5, pady=5, sticky=W + E)
input_button.drop_target_register(DND_FILES)
input_button.dnd_bind("<<Drop>>", video_drop_input)
input_entry = Entry(video_tab, borderwidth=4, background="#CACACA", state=DISABLED)
input_entry.grid(row=0, column=1, columnspan=2, padx=(5, 0), pady=5, sticky=W + E)
input_entry.drop_target_register(DND_FILES)
input_entry.dnd_bind("<<Drop>>", video_drop_input)
def clear_video_input(): # When user selects 'X' to clear input box
global VideoInput, video_title_cmd_input, video_title_entrybox, video_combo_language, input_entry
try:
video_title_cmd_input = ""
video_title_entrybox.configure(state=NORMAL)
video_title_entrybox.delete(0, END)
video_title_entrybox.configure(state=DISABLED)
video_combo_language.current(0)
input_entry.configure(state=NORMAL)
input_entry.delete(0, END)
input_entry.configure(state=DISABLED)
del VideoInput
except (Exception,):
pass
delete_input_button = HoverButton(
video_tab,
text="X",
command=clear_video_input,
foreground="white",
background="#23272A",
borderwidth="3",
activebackground="grey",
width=2,
)
delete_input_button.grid(row=0, column=3, columnspan=1, padx=10, pady=5, sticky=E)
# ------------------------------------------------------------------------------------------------------------- Buttons
# --------------------------------------------------------------------------------------------------------- Video Frame
# Audio --------------------------------------------------------------------------------------------------------------
audio_frame = LabelFrame(mp4_root, text=" Audio ")
audio_frame.grid(row=1, columnspan=4, sticky=E + W + N + S, padx=20, pady=(5, 5))
audio_frame.configure(fg="white", bg="#434547", bd=4)
audio_frame.grid_columnconfigure(0, weight=1)
audio_frame.grid_rowconfigure(0, weight=1)
# Audio Notebook Frame ------------------------------------------------------------------------------------------------
tabs = ttk.Notebook(audio_frame, height=110)
tabs.grid(row=0, column=0, columnspan=4, sticky=E + W + N + S, padx=10, pady=5)
audio_tab = Frame(tabs, background="#434547")
tabs.add(audio_tab, text=" Track #1 ")
for n in range(4):
audio_tab.grid_columnconfigure(n, weight=1)
audio_tab.grid_columnconfigure(0, weight=1, minsize=120)
audio_tab.grid_columnconfigure(1, weight=100)
for n in range(3):
audio_tab.grid_rowconfigure(n, weight=1)
# ------------------------------------------------------------------------------------------------ Audio Notebook Frame
# Entry Box for Audio Title -------------------------------------------------------------------------------------------
def audio_title(*args):
global audio_title_cmd_input
if audio_title_cmd.get().strip() == "":
audio_title_cmd_input = ":name="
else:
audio_title_cmd_input = ":name=" + audio_title_cmd.get().strip()
audio_title_cmd = StringVar()
audio_title_entrybox_label = Label(
audio_tab, text="Audio Title:", anchor=W, background="#434547", foreground="white"
)
audio_title_entrybox_label.grid(
row=1, column=1, columnspan=1, padx=10, pady=(0, 0), sticky=W
)
audio_title_entrybox = Entry(
audio_tab,
textvariable=audio_title_cmd,
borderwidth=4,
background="#CACACA",
state=DISABLED,
)
audio_title_entrybox.grid(
row=2, column=1, columnspan=2, padx=10, pady=(0, 15), sticky=W + E
)
audio_title_cmd.trace("w", audio_title)
audio_title_cmd.set("")
# ------------------------------------------------------------------------------------------- Entry Box for Audio Title
# Audio Delay Selection -----------------------------------------------------------------------------------------------
audio_delay = StringVar()
audio_delay_label = Label(
audio_tab, text="Delay:", background="#434547", foreground="white"
)
audio_delay_label.grid(row=1, column=3, columnspan=1, padx=10, pady=1, sticky=W)
audio_delay_spinbox = Spinbox(
audio_tab,
from_=0,
to=20000,
increment=1.0,
justify=CENTER,
wrap=True,
textvariable=audio_delay,
width=14,
)
audio_delay_spinbox.configure(
background="#23272A",
foreground="white",
highlightthickness=1,
buttonbackground="black",
readonlybackground="#23272A",
)
audio_delay_spinbox.grid(row=2, column=3, columnspan=1, padx=10, pady=(1, 8), sticky=W)
audio_delay.set(0)
# --------------------------------------------------------------------------------------------------------- Audio Delay
# Audio Language Selection --------------------------------------------------------------------------------------------
audio_language = StringVar()
audio_language_menu_label = Label(
audio_tab, text="Language:", background="#434547", foreground="white"
)
audio_language_menu_label.grid(
row=1, column=0, columnspan=1, padx=10, pady=(0, 0), sticky=W
)
audio_language = ttk.Combobox(
audio_tab,
values=list(iso_639_2_codes_dictionary.keys()),
justify="center",
textvariable=audio_language,
)
audio_language.grid(
row=2, column=0, columnspan=1, padx=10, pady=(0, 10), sticky=N + S + W + E
)
audio_language["state"] = "readonly"
audio_language.current(0)
# ------------------------------------------------------------------------------------------------------ Audio Language
# Audio Stream Selection ----------------------------------------------------------------------------------
def check_audio_tracks_info():
global audio_input
def audio_track_choice(): # If audio input has only 1 audio track