-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
131 lines (109 loc) · 5.24 KB
/
main.py
File metadata and controls
131 lines (109 loc) · 5.24 KB
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
import os
import json
import threading
import tkinter as tk
from tkinter import filedialog, messagebox
from tkinter import ttk
from pathlib import Path
from effects import effects_registry, apply_effects_with_pipeline
from utils import randomize_effect_selections, ensure_tmpdir
# Constants
PRESETS_FILE = Path(__file__).with_name("presets.json")
class YTPDeluxeGUI:
def __init__(self, root):
self.root = root
root.title("YTP+ Deluxe Edition — Python + FFmpeg (Tkinter GUI)")
self.input_path = None
# Top frame: File controls
top = ttk.Frame(root, padding=8)
top.pack(fill="x")
self.open_btn = ttk.Button(top, text="Open File...", command=self.open_file)
self.open_btn.pack(side="left")
self.input_label = ttk.Label(top, text="No file selected")
self.input_label.pack(side="left", padx=8)
# Middle: Effects list with checkboxes
mid = ttk.Frame(root, padding=8)
mid.pack(fill="both", expand=True)
self.effects_vars = {}
ttk.Label(mid, text="Effects:").pack(anchor="w")
effects_frame = ttk.Frame(mid)
effects_frame.pack(fill="both", expand=True)
# Scrollable effects list
canvas = tk.Canvas(effects_frame, height=380)
scrollbar = ttk.Scrollbar(effects_frame, orient="vertical", command=canvas.yview)
self.checks_frame = ttk.Frame(canvas)
self.checks_frame.bind(
"<Configure>",
lambda e: canvas.configure(scrollregion=canvas.bbox("all"))
)
canvas.create_window((0, 0), window=self.checks_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
# Populate effect checkbuttons
for key, meta in effects_registry.items():
var = tk.IntVar(value=0)
cb = ttk.Checkbutton(self.checks_frame, text=meta["display_name"], variable=var)
cb.pack(anchor="w")
self.effects_vars[key] = var
# Bottom: Controls
bottom = ttk.Frame(root, padding=8)
bottom.pack(fill="x")
controls = ttk.Frame(bottom)
controls.pack(side="left", padx=4)
ttk.Label(controls, text="Effect Probability (for Randomize)").grid(row=0, column=0, sticky="w")
self.prob_scale = ttk.Scale(controls, from_=0, to=100, orient="horizontal")
self.prob_scale.set(50)
self.prob_scale.grid(row=0, column=1, padx=6, sticky="we")
ttk.Label(controls, text="Max Effect Level").grid(row=1, column=0, sticky="w")
self.level_scale = ttk.Scale(controls, from_=0, to=100, orient="horizontal")
self.level_scale.set(75)
self.level_scale.grid(row=1, column=1, padx=6, sticky="we")
# Buttons
btn_frame = ttk.Frame(bottom)
btn_frame.pack(side="right")
self.random_btn = ttk.Button(btn_frame, text="Randomize", command=self.randomize_effects)
self.random_btn.pack(side="left", padx=4)
self.process_btn = ttk.Button(btn_frame, text="Process", command=self.process_file)
self.process_btn.pack(side="left", padx=4)
# Load presets (if any)
self.presets = {}
if PRESETS_FILE.exists():
with open(PRESETS_FILE, "r", encoding="utf-8") as f:
self.presets = json.load(f)
def open_file(self):
filetypes = [("Video or audio", "*.mp4 *.mkv *.avi *.mov *.mp3 *.wav *.flac"), ("All files", "*.*")]
path = filedialog.askopenfilename(title="Select input file", filetypes=filetypes)
if path:
self.input_path = Path(path)
self.input_label.config(text=str(self.input_path))
def randomize_effects(self):
prob = int(self.prob_scale.get())
selections = randomize_effect_selections(list(self.effects_vars.keys()), prob)
for k, var in self.effects_vars.items():
var.set(1 if selections.get(k, False) else 0)
def process_file(self):
if not self.input_path or not self.input_path.exists():
messagebox.showerror("No input", "Please open an input file first.")
return
selected = [k for k, v in self.effects_vars.items() if v.get() == 1]
prob = int(self.prob_scale.get())
max_level = int(self.level_scale.get())
out_path = self.input_path.with_name(self.input_path.stem + "_ytp_plus_deluxe" + self.input_path.suffix)
tmpdir = ensure_tmpdir()
# Run in background thread
t = threading.Thread(target=self._run_processing, args=(str(self.input_path), str(out_path), selected, prob, max_level, tmpdir), daemon=True)
t.start()
messagebox.showinfo("Processing", f"Processing started. Output will be: {out_path}")
def _run_processing(self, input_path, output_path, selected_effects, prob, max_level, tmpdir):
try:
apply_effects_with_pipeline(input_path, output_path, selected_effects, prob, max_level, tmpdir)
messagebox.showinfo("Done", f"Processing complete.\nOutput: {output_path}")
except Exception as e:
messagebox.showerror("Error", f"Processing failed: {e}")
def main():
root = tk.Tk()
app = YTPDeluxeGUI(root)
root.mainloop()
if __name__ == "__main__":
main()