-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui_app.py
More file actions
736 lines (613 loc) · 31.4 KB
/
Copy pathgui_app.py
File metadata and controls
736 lines (613 loc) · 31.4 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
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
import os
import subprocess
import glob
import tkinter as tk
from tkinter import ttk, filedialog, messagebox, scrolledtext
import threading
from pathlib import Path
import json
import sys
from datetime import datetime
class TrackSplitterGUI:
def __init__(self, root):
self.root = root
self.root.title("SL Track Splitter Pro")
self.root.geometry("950x750")
self.root.minsize(850, 650)
self.root.resizable(True, True)
# Window setup
self.set_window_icon()
# Center window
self.center_window()
# Theme setup
self.setup_theme()
# App variables
self.chunk_duration = tk.DoubleVar(value=4.99)
self.sample_rate = tk.StringVar(value="44100")
self.channels = tk.StringVar(value="1")
self.sample_format = tk.StringVar(value="s16")
self.output_format = tk.StringVar(value="wav")
self.input_files = []
self.processing = False
self.fade_in = tk.BooleanVar(value=False)
self.fade_out = tk.BooleanVar(value=False)
self.fade_duration = tk.DoubleVar(value=0.1)
self.normalize = tk.BooleanVar(value=True)
self.quality_preset = tk.StringVar(value="medium")
self.output_naming = tk.StringVar(value="default")
self.custom_name_format = tk.StringVar(value="track{number}")
self.auto_open = tk.BooleanVar(value=True)
self.preview_mode = tk.BooleanVar(value=False)
# FFmpeg check
self.ffmpeg_path = self.check_ffmpeg()
# GUI creation
self.create_widgets()
# Settings load
self.load_settings()
def setup_theme(self):
style = ttk.Style()
style.theme_use('clam')
# Color scheme
bg_primary = '#1a1a1a' # Deep black
bg_secondary = '#252525' # Dark gray
bg_card = '#2d2d2d' # Card background
fg_primary = '#ffffff' # White text
fg_secondary = '#b0b0b0' # Gray text
accent_cyan = '#00d4ff' # Bright cyan
accent_purple = '#8b5cf6' # Purple accent
accent_green = '#10b981' # Success green
accent_orange = '#f59e0b' # Warning orange
accent_red = '#ef4444' # Error red
# Color storage
self.colors = {
'bg_primary': bg_primary,
'bg_secondary': bg_secondary,
'bg_card': bg_card,
'fg_primary': fg_primary,
'fg_secondary': fg_secondary,
'accent_cyan': accent_cyan,
'accent_purple': accent_purple,
'accent_green': accent_green,
'accent_orange': accent_orange,
'accent_red': accent_red
}
# Style configuration
style.configure('Title.TLabel',
background=bg_primary,
foreground=accent_cyan,
font=('Segoe UI', 20, 'bold'))
style.configure('Heading.TLabel',
background=bg_card,
foreground=accent_cyan,
font=('Segoe UI', 12, 'bold'))
style.configure('Modern.TLabel',
background=bg_card,
foreground=fg_primary,
font=('Segoe UI', 10))
style.configure('Modern.TButton',
background=accent_cyan,
foreground=bg_primary,
font=('Segoe UI', 10, 'bold'),
padding=(20, 10),
relief='flat',
borderwidth=0,
focuscolor='none')
style.map('Modern.TButton',
background=[('active', '#00b8e6'), ('pressed', '#00a8d6')])
style.configure('Success.TButton',
background=accent_green,
foreground='white',
font=('Segoe UI', 11, 'bold'),
padding=(25, 12),
relief='flat',
borderwidth=0,
focuscolor='none')
style.map('Success.TButton',
background=[('active', '#059669'), ('pressed', '#047857')])
style.configure('Card.TFrame',
background=bg_card,
relief='flat',
borderwidth=0)
style.configure('Modern.TFrame',
background=bg_primary,
relief='flat',
borderwidth=0)
style.configure('Modern.TLabelframe',
background=bg_card,
foreground=accent_cyan,
font=('Segoe UI', 11, 'bold'),
relief='flat',
borderwidth=0,
padding=(10, 5))
style.configure('Modern.TLabelframe.Label',
background=bg_card,
foreground=accent_cyan,
font=('Segoe UI', 11, 'bold'))
style.configure('Modern.TEntry',
fieldbackground=bg_secondary,
foreground=fg_primary,
borderwidth=1,
relief='solid',
bordercolor=accent_cyan,
insertcolor=accent_cyan,
font=('Segoe UI', 10))
style.configure('Modern.TCombobox',
fieldbackground=bg_secondary,
foreground=fg_primary,
borderwidth=1,
relief='solid',
bordercolor=accent_cyan,
font=('Segoe UI', 10))
# Background apply
self.root.configure(bg=bg_primary)
def set_window_icon(self):
try:
# Load icon if available
icon_path = os.path.join(os.getcwd(), "icon.ico")
if os.path.exists(icon_path):
self.root.iconbitmap(icon_path)
else:
# Create icon if missing
pass # We'll create the icon file separately
except:
pass # Continue without icon if there's an error
def center_window(self):
self.root.update_idletasks()
width = self.root.winfo_width()
height = self.root.winfo_height()
x = (self.root.winfo_screenwidth() // 2) - (width // 2)
y = (self.root.winfo_screenheight() // 2) - (height // 2)
self.root.geometry(f'{width}x{height}+{x}+{y}')
def check_ffmpeg(self):
# Check bundled version
if hasattr(sys, '_MEIPASS'):
# PyInstaller path
bundle_dir = sys._MEIPASS
ffmpeg_path = os.path.join(bundle_dir, "ffmpeg.exe")
if os.path.exists(ffmpeg_path):
return ffmpeg_path
# Check local directory
ffmpeg_path = os.path.join(os.getcwd(), "ffmpeg.exe")
if os.path.exists(ffmpeg_path):
return ffmpeg_path
# Check system PATH
try:
subprocess.run(["ffmpeg", "-version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
return "ffmpeg"
except (subprocess.CalledProcessError, FileNotFoundError):
pass
# Error if not found
messagebox.showerror("Error",
"FFmpeg not found!\n\nPlease ensure ffmpeg.exe is in the same folder as the application.\n" +
"You can download FFmpeg from: https://ffmpeg.org/download.html")
self.root.quit()
return None
def create_widgets(self):
# Main frame
main_frame = ttk.Frame(self.root, style='Modern.TFrame', padding="20")
main_frame.pack(fill=tk.BOTH, expand=True)
# Grid setup
self.root.columnconfigure(0, weight=1)
self.root.rowconfigure(0, weight=1)
main_frame.columnconfigure(0, weight=1)
main_frame.rowconfigure(5, weight=1) # Log section expands
# Title section
title_frame = ttk.Frame(main_frame, style='Modern.TFrame')
title_frame.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=(0, 25))
title_frame.columnconfigure(0, weight=1)
title_container = tk.Frame(title_frame, bg=self.colors['bg_primary'])
title_container.pack(fill=tk.X)
title_label = ttk.Label(title_container, text="🎵 SL Track Splitter Pro", style='Title.TLabel')
title_label.pack(side=tk.LEFT)
self.status_indicator = tk.Label(title_container, text="●", fg=self.colors['accent_green'],
bg=self.colors['bg_primary'], font=('Segoe UI', 18, 'bold'))
self.status_indicator.pack(side=tk.LEFT, padx=(15, 0))
subtitle_label = tk.Label(title_container, text="by salty.spicy", fg=self.colors['fg_secondary'],
bg=self.colors['bg_primary'], font=('Segoe UI', 11, 'italic'))
subtitle_label.pack(side=tk.LEFT, padx=(20, 0))
# Version badge
version_badge = tk.Label(title_container, text="v2.0", fg=self.colors['accent_purple'],
bg=self.colors['bg_primary'], font=('Segoe UI', 9, 'bold'))
version_badge.pack(side=tk.RIGHT)
# File section
file_frame = ttk.LabelFrame(main_frame, text="📁 File Selection", style='Modern.TLabelframe', padding="12")
file_frame.grid(row=1, column=0, sticky=(tk.W, tk.E), pady=(0, 15))
file_frame.columnconfigure(1, weight=1)
ttk.Button(file_frame, text="Select Audio Files", command=self.select_files, style='Modern.TButton').grid(row=0, column=0, padx=(0, 12))
self.file_listbox = tk.Listbox(file_frame, height=3, bg=self.colors['bg_secondary'], fg=self.colors['fg_primary'],
font=('Consolas', 9), selectbackground=self.colors['accent_cyan'],
selectforeground=self.colors['bg_primary'], relief='solid', bd=1,
highlightthickness=0)
self.file_listbox.grid(row=0, column=1, sticky=(tk.W, tk.E), padx=(0, 12))
ttk.Button(file_frame, text="Clear", command=self.clear_files, style='Modern.TButton').grid(row=0, column=2)
# Settings section
settings_frame = ttk.LabelFrame(main_frame, text="⚙️ Settings", style='Modern.TLabelframe', padding="12")
settings_frame.grid(row=2, column=0, sticky=(tk.W, tk.E), pady=(0, 15))
settings_frame.columnconfigure(1, weight=1)
# Duration control
ttk.Label(settings_frame, text="Chunk Duration (seconds):", style='Modern.TLabel').grid(row=0, column=0, sticky=tk.W, pady=6)
duration_frame = ttk.Frame(settings_frame, style='Modern.TFrame')
duration_frame.grid(row=0, column=1, sticky=(tk.W, tk.E), pady=6)
duration_frame.columnconfigure(0, weight=1)
ttk.Scale(duration_frame, from_=1.0, to=30.0, variable=self.chunk_duration, orient=tk.HORIZONTAL).grid(row=0, column=0, sticky=(tk.W, tk.E))
self.duration_entry = ttk.Entry(duration_frame, textvariable=self.chunk_duration, width=8, style='Modern.TEntry')
self.duration_entry.grid(row=0, column=1, padx=(12, 5))
self.duration_label = ttk.Label(duration_frame, text="s", style='Modern.TLabel')
self.duration_label.grid(row=0, column=2)
self.chunk_duration.trace('w', self.update_duration_label)
# SL presets
ttk.Label(settings_frame, text="Second Life Presets:", style='Modern.TLabel').grid(row=1, column=0, sticky=tk.W, pady=6)
preset_frame = ttk.Frame(settings_frame, style='Modern.TFrame')
preset_frame.grid(row=1, column=1, sticky=tk.W, pady=6)
ttk.Button(preset_frame, text="SL 4.99s", command=self.apply_sl_preset_4_99, style='Modern.TButton').pack(side=tk.LEFT, padx=(0, 6))
ttk.Button(preset_frame, text="SL 9.99s", command=self.apply_sl_preset_9_99, style='Modern.TButton').pack(side=tk.LEFT, padx=(0, 6))
ttk.Button(preset_frame, text="SL 29.99s", command=self.apply_sl_preset_29_99, style='Modern.TButton').pack(side=tk.LEFT, padx=(0, 12))
ttk.Label(preset_frame, text="(44.1kHz, Mono, 16-bit)", foreground='#888888', font=('Segoe UI', 9)).pack(side=tk.LEFT)
# Audio settings
audio_frame = ttk.Frame(settings_frame, style='Modern.TFrame')
audio_frame.grid(row=2, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=6)
audio_frame.columnconfigure(1, weight=1)
audio_frame.columnconfigure(3, weight=1)
audio_frame.columnconfigure(5, weight=1)
ttk.Label(audio_frame, text="Sample Rate:", style='Modern.TLabel').grid(row=0, column=0, sticky=tk.W, padx=(0, 5))
sample_rate_combo = ttk.Combobox(audio_frame, textvariable=self.sample_rate, values=["22050", "44100", "48000"], width=10, style='Modern.TCombobox')
sample_rate_combo.grid(row=0, column=1, sticky=tk.W)
ttk.Label(audio_frame, text="Channels:", style='Modern.TLabel').grid(row=0, column=2, sticky=tk.W, padx=(20, 5))
channel_combo = ttk.Combobox(audio_frame, textvariable=self.channels, values=["1 (Mono)", "2 (Stereo)"], width=10, style='Modern.TCombobox')
channel_combo.grid(row=0, column=3, sticky=tk.W)
channel_combo.bind('<<ComboboxSelected>>', self.update_channels)
ttk.Label(audio_frame, text="Format:", style='Modern.TLabel').grid(row=0, column=4, sticky=tk.W, padx=(20, 5))
format_combo = ttk.Combobox(audio_frame, textvariable=self.output_format, values=["wav", "mp3"], width=8, style='Modern.TCombobox')
format_combo.grid(row=0, column=5, sticky=tk.W)
# Naming options
naming_frame = ttk.Frame(settings_frame, style='Modern.TFrame')
naming_frame.grid(row=3, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=6)
naming_frame.columnconfigure(1, weight=1)
naming_frame.columnconfigure(3, weight=1)
ttk.Label(naming_frame, text="Output Naming:", style='Modern.TLabel').grid(row=0, column=0, sticky=tk.W, padx=(0, 5))
naming_combo = ttk.Combobox(naming_frame, textvariable=self.output_naming,
values=["default", "custom", "sequential", "timestamp"],
width=12, style='Modern.TCombobox')
naming_combo.grid(row=0, column=1, sticky=tk.W)
naming_combo.bind('<<ComboboxSelected>>', self.update_naming_field)
self.custom_name_entry = ttk.Entry(naming_frame, textvariable=self.custom_name_format,
width=20, style='Modern.TEntry')
self.custom_name_entry.grid(row=0, column=2, padx=(10, 5))
help_label = ttk.Label(naming_frame, text="Use {name} for original name, {number} for part",
foreground='#888888', font=('Segoe UI', 8))
help_label.grid(row=0, column=3, sticky=tk.W)
# Hide custom field initially
self.update_naming_field()
# Buttons
button_frame = ttk.Frame(main_frame, style='Modern.TFrame')
button_frame.grid(row=3, column=0, pady=15)
self.process_button = ttk.Button(button_frame, text="🚀 Process Files", command=self.process_files, style='Success.TButton')
self.process_button.pack(side=tk.LEFT, padx=(0, 12))
ttk.Button(button_frame, text="📂 Open Output", command=self.open_output_folder, style='Modern.TButton').pack(side=tk.LEFT)
# Progress section
progress_frame = ttk.LabelFrame(main_frame, text="📊 Progress", style='Modern.TLabelframe', padding="10")
progress_frame.grid(row=4, column=0, sticky=(tk.W, tk.E), pady=(0, 15))
progress_frame.columnconfigure(0, weight=1)
self.progress_var = tk.DoubleVar()
self.progress_bar = ttk.Progressbar(progress_frame, variable=self.progress_var, maximum=100)
self.progress_bar.grid(row=0, column=0, sticky=(tk.W, tk.E), pady=(0, 8))
self.status_label = ttk.Label(progress_frame, text="Ready to process files...", style='Modern.TLabel')
self.status_label.grid(row=1, column=0, sticky=tk.W)
# Log section
log_frame = ttk.LabelFrame(main_frame, text="📝 Activity Log", style='Modern.TLabelframe', padding="12")
log_frame.grid(row=5, column=0, sticky=(tk.W, tk.E, tk.N, tk.S), pady=(0, 0))
log_frame.columnconfigure(0, weight=1)
log_frame.rowconfigure(0, weight=1)
self.log_text = scrolledtext.ScrolledText(log_frame, wrap=tk.WORD, bg=self.colors['bg_secondary'],
fg=self.colors['accent_cyan'], font=('Consolas', 9),
insertbackground=self.colors['accent_cyan'], relief='solid',
bd=1, highlightthickness=0, selectbackground=self.colors['accent_cyan'],
selectforeground=self.colors['bg_primary'])
self.log_text.grid(row=0, column=0, sticky=(tk.W, tk.E, tk.N, tk.S))
# Welcome messages
self.log("🎵 Welcome to SL Track Splitter Pro!", "system")
self.log("👨💻 Created by salty.spicy (salty_a)", "system")
self.log("🚀 Ready to process your audio files...", "ready")
self.log("💡 Tip: Use SL presets for optimal Second Life uploads", "info")
# Menu creation
self.create_menu()
def create_menu(self):
menubar = tk.Menu(self.root)
self.root.config(menu=menubar)
# File menu
file_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Select Files", command=self.select_files)
file_menu.add_command(label="Open Output Folder", command=self.open_output_folder)
file_menu.add_separator()
file_menu.add_command(label="Exit", command=self.root.quit)
# Settings menu
settings_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="Settings", menu=settings_menu)
settings_menu.add_command(label="Apply SL Preset", command=self.apply_sl_preset)
settings_menu.add_command(label="Reset to Defaults", command=self.reset_settings)
# Help menu
help_menu = tk.Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=help_menu)
help_menu.add_command(label="About", command=self.show_about)
def update_status_indicator(self, status):
colors = {
"ready": self.colors['accent_green'],
"processing": self.colors['accent_orange'],
"error": self.colors['accent_red'],
"success": self.colors['accent_cyan']
}
self.status_indicator.config(fg=colors.get(status, self.colors['accent_green']))
def update_duration_label(self, *args):
try:
value = self.chunk_duration.get()
if value and str(value).strip():
self.duration_label.config(text=f"{float(value):.2f}s")
else:
self.duration_label.config(text="s")
except (ValueError, tk.TclError):
self.duration_label.config(text="s")
def update_naming_field(self, event=None):
naming_type = self.output_naming.get()
if naming_type == "custom":
self.custom_name_entry.grid(row=0, column=2, padx=(10, 5))
else:
self.custom_name_entry.grid_remove()
def generate_filename(self, base_name, part_number, total_parts):
naming_type = self.output_naming.get()
if naming_type == "default":
# Default naming
return f"{base_name}_part{part_number:03d}"
elif naming_type == "custom":
# Custom format
custom_format = self.custom_name_format.get()
filename = custom_format.replace("{name}", base_name)
filename = filename.replace("{number}", str(part_number))
filename = filename.replace("{total}", str(total_parts))
return filename
elif naming_type == "sequential":
# Sequential naming
return f"track{part_number}"
elif naming_type == "timestamp":
# Timestamp naming
from datetime import datetime
timestamp = datetime.now().strftime("%H%M%S")
return f"track_{timestamp}_{part_number:03d}"
else:
# Fallback
return f"{base_name}_part{part_number:03d}"
def update_channels(self, event=None):
selection = self.channels.get()
if "1" in selection:
self.channels.set("1")
else:
self.channels.set("2")
def apply_sl_preset(self):
self.chunk_duration.set(4.99)
self.sample_rate.set("44100")
self.channels.set("1")
self.sample_format.set("s16")
self.output_format.set("wav")
self.log("Applied Second Life preset (4.99s chunks, 44.1kHz, Mono, 16-bit WAV)")
def apply_sl_preset_4_99(self):
self.chunk_duration.set(4.99)
self.sample_rate.set("44100")
self.channels.set("1")
self.sample_format.set("s16")
self.output_format.set("wav")
self.log("Applied SL 4.99s preset - Perfect for standard SL uploads!")
def apply_sl_preset_9_99(self):
self.chunk_duration.set(9.99)
self.sample_rate.set("44100")
self.channels.set("1")
self.sample_format.set("s16")
self.output_format.set("wav")
self.log("Applied SL 9.99s preset - Maximum duration for SL!")
def apply_sl_preset_29_99(self):
self.chunk_duration.set(29.99)
self.sample_rate.set("44100")
self.channels.set("1")
self.sample_format.set("s16")
self.output_format.set("wav")
self.log("Applied SL 29.99s preset - Extended duration for SL!")
def reset_settings(self):
self.chunk_duration.set(4.99)
self.sample_rate.set("44100")
self.channels.set("1")
self.sample_format.set("s16")
self.output_format.set("wav")
self.log("Settings reset to defaults")
def select_files(self):
files = filedialog.askopenfilenames(
title="Select Audio Files",
filetypes=[
("Audio Files", "*.wav *.mp3 *.flac *.aac *.ogg"),
("WAV Files", "*.wav"),
("MP3 Files", "*.mp3"),
("All Files", "*.*")
]
)
if files:
self.input_files = list(files)
self.file_listbox.delete(0, tk.END)
for file in self.input_files:
self.file_listbox.insert(tk.END, os.path.basename(file))
self.log(f"Selected {len(files)} file(s)")
def clear_files(self):
self.input_files = []
self.file_listbox.delete(0, tk.END)
self.log("Cleared file selection")
def process_files(self):
if not self.input_files:
messagebox.showwarning("Warning", "Please select audio files first!")
return
if self.processing:
messagebox.showwarning("Warning", "Already processing files!")
return
self.processing = True
self.process_button.config(state='disabled')
self.progress_var.set(0)
self.status_label.config(text=" Processing files...")
self.update_status_indicator("processing")
# Start background processing
thread = threading.Thread(target=self.process_files_thread)
thread.daemon = True
thread.start()
def process_files_thread(self):
try:
total_files = len(self.input_files)
for i, file_path in enumerate(self.input_files):
self.status_label.config(text=f"Processing {os.path.basename(file_path)}...")
self.log(f"Processing: {os.path.basename(file_path)}")
base_name = os.path.splitext(os.path.basename(file_path))[0]
output_dir = f"{base_name}_splits"
# Create output folder
os.makedirs(output_dir, exist_ok=True)
# Get file duration
ffprobe_path = self.ffmpeg_path.replace("ffmpeg.exe", "ffprobe.exe") if "ffmpeg.exe" in self.ffmpeg_path else "ffprobe"
result = subprocess.run(
[ffprobe_path,
"-v", "error",
"-show_entries", "format=duration",
"-of", "default=noprint_wrappers=1:nokey=1",
file_path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
try:
total_duration = float(result.stdout)
except ValueError:
self.log(f"❌ Failed to read duration of {os.path.basename(file_path)}")
continue
# Split file
chunk_duration = self.chunk_duration.get()
part = 1
start = 0
chunks_created = 0
# Calculate parts
total_parts = int(total_duration / chunk_duration) + 1
while start < total_duration:
filename = self.generate_filename(base_name, part, total_parts)
out_path = os.path.join(output_dir, f"{filename}.{self.output_format.get()}")
# Build FFmpeg command
cmd = [
self.ffmpeg_path,
"-ss", str(start),
"-t", str(chunk_duration),
"-i", file_path,
"-ar", self.sample_rate.get(),
"-ac", self.channels.get(),
"-sample_fmt", self.sample_format.get(),
"-y",
out_path
]
# Format options
if self.output_format.get() == "mp3":
cmd.extend(["-codec:a", "libmp3lame", "-q:a", "2"])
elif self.output_format.get() == "flac":
cmd.extend(["-codec:a", "flac", "-compression_level", "8"])
elif self.output_format.get() == "aac":
cmd.extend(["-codec:a", "aac", "-b:a", "192k"])
# Run command
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
self.log(f"✅ Created: {os.path.basename(out_path)}")
chunks_created += 1
start += chunk_duration
part += 1
self.log(f"📁 Created {chunks_created} chunks in {output_dir}/")
# Update progress
progress = ((i + 1) / total_files) * 100
self.progress_var.set(progress)
self.status_label.config(text="✅ All files processed successfully!")
self.update_status_indicator("success")
self.log("🎉 All files processed successfully!")
messagebox.showinfo("Success", f"Processed {total_files} file(s) successfully!")
except Exception as e:
self.log(f"❌ Error: {str(e)}")
self.update_status_indicator("error")
messagebox.showerror("Error", f"An error occurred: {str(e)}")
finally:
self.processing = False
self.process_button.config(state='normal')
self.update_status_indicator("ready")
def open_output_folder(self):
if self.input_files:
# Open first output folder
base_name = os.path.splitext(os.path.basename(self.input_files[0]))[0]
output_dir = f"{base_name}_splits"
if os.path.exists(output_dir):
os.startfile(output_dir)
else:
messagebox.showinfo("Info", "Output folder doesn't exist yet. Process files first.")
else:
messagebox.showinfo("Info", "Please select files first.")
def log(self, message, msg_type="normal"):
timestamp = datetime.now().strftime("%H:%M:%S")
# Color setup
colors = {
"system": self.colors['accent_purple'],
"ready": self.colors['accent_green'],
"info": self.colors['accent_orange'],
"success": self.colors['accent_green'],
"error": self.colors['accent_red'],
"warning": self.colors['accent_orange'],
"normal": self.colors['accent_cyan']
}
color = colors.get(msg_type, self.colors['accent_cyan'])
self.log_text.tag_config(msg_type, foreground=color)
self.log_text.insert(tk.END, f"[{timestamp}] {message}\n", msg_type)
self.log_text.see(tk.END)
self.root.update_idletasks()
def show_about(self):
about_text = """🎵 SL Track Splitter Pro v2.0
A premium modern tool for splitting audio tracks into chunks optimized for Second Life.
✨ Features:
• Customizable chunk duration with precise input
• Triple Second Life presets (4.99s, 9.99s, 29.99s)
• Support for multiple audio formats
• Modern dark theme interface
• Real-time progress tracking
• Professional audio processing
👨💻 Created by: salty.spicy (salty_a) in Second Life
🎮 Find me inworld: salty.spicy
💬 Discord: salty_a
Made with ❤️ for Second Life content creators!"""
messagebox.showinfo("About SL Track Splitter Pro", about_text)
def load_settings(self):
settings_file = "track_splitter_settings.json"
if os.path.exists(settings_file):
try:
with open(settings_file, 'r') as f:
settings = json.load(f)
self.chunk_duration.set(settings.get('chunk_duration', 4.99))
self.sample_rate.set(settings.get('sample_rate', '44100'))
self.channels.set(settings.get('channels', '1'))
self.sample_format.set(settings.get('sample_format', 's16'))
self.output_format.set(settings.get('output_format', 'wav'))
except:
pass
def save_settings(self):
settings_file = "track_splitter_settings.json"
settings = {
'chunk_duration': self.chunk_duration.get(),
'sample_rate': self.sample_rate.get(),
'channels': self.channels.get(),
'sample_format': self.sample_format.get(),
'output_format': self.output_format.get()
}
try:
with open(settings_file, 'w') as f:
json.dump(settings, f, indent=2)
except:
pass
def main():
root = tk.Tk()
app = TrackSplitterGUI(root)
# Save on exit
def on_closing():
app.save_settings()
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()
if __name__ == "__main__":
main()