Skip to content

Commit 46b219f

Browse files
committed
Find and replace
added find and replace functionality
1 parent 18c906a commit 46b219f

2 files changed

Lines changed: 44 additions & 13 deletions

File tree

ABS.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from pydub import AudioSegment, effects
66

77

8-
### color settings
8+
### Color settings
99

1010
scolor="violetred3"
1111
scolor2="DeepPink4"
@@ -20,7 +20,8 @@
2020
sg.In(size=(25,1), enable_events=True ,key='-FOLDER-',background_color="snow1", readonly=True),
2121
sg.FolderBrowse(button_color=scolor),
2222
sg.Checkbox('Iterate down folder tree? (Recursive)', key="-REC-", enable_events=True, background_color=scolor),
23-
sg.Checkbox('Show paths?', key="-SHOWPATHS-", enable_events=True, background_color=scolor)
23+
sg.Checkbox('Show paths?', key="-SHOWPATHS-", enable_events=True, background_color=scolor),
24+
sg.Button("Refresh", button_color=scolor)
2425
]]
2526

2627
filelist = [sg.Listbox([], size=(0,16), key= '-LIST-', background_color=bgcolor, text_color="white", expand_x=True, sbar_background_color=scolor)]
@@ -40,7 +41,8 @@
4041
expand_y=True)
4142

4243
modulecol2 = sg.Column([
43-
[sg.Checkbox('Prefix', key="-PREFIXBOOL-", background_color=bgcolor), sg.In(size=(10,0), key="-PREFIXSTR-")]
44+
[sg.Checkbox('Prefix', key="-PREFIXBOOL-", background_color=bgcolor), sg.In(size=(10,0), key="-PREFIXSTR-")],
45+
[sg.Checkbox('Replace Text', key="-REPL-", background_color=bgcolor), sg.In(size=(10,0), key="-RPLFROM-", enable_events=True), sg.Text('>>>', background_color=bgcolor), sg.In(size=(10,0), key="-RPLTO-")]
4446
],
4547
vertical_alignment="top",
4648
background_color=bgcolor,
@@ -63,7 +65,7 @@
6365
window = sg.Window('ABS', layout,resizable=True, finalize=True, background_color=windowcolor, size=(960,712))
6466

6567

66-
### helpers
68+
### Helpers
6769

6870
def getfilenames(paths):
6971
fnames = []
@@ -138,13 +140,28 @@ def rmempty(files, FLStudio):
138140
os.remove(file)
139141

140142
def setprefix(files, prefix):
143+
curproc = 0
141144
for file in files:
142145
fname = os.path.basename(file)
143146
d = os.path.dirname(file)
144-
filelog("Renamed to " + prefix + fname)
145147
os.rename(file, d + "/" + prefix + fname)
146-
sleep(1)
147-
updatefilelist(values["-SHOWPATHS-"], files)
148+
filelog("Renamed to " + prefix + fname)
149+
curproc += 1
150+
if curproc == len(files):
151+
updatefilelist(values["-SHOWPATHS-"], getfiles(d, values['-REC-']))
152+
153+
def findrepl(files, rplfrom, rplto):
154+
curproc = 0
155+
for file in files:
156+
fname = os.path.basename(file)
157+
newfname = fname.replace(rplfrom, rplto)
158+
d = os.path.dirname(file)
159+
filelog("Renamed " + fname + " to " + newfname)
160+
os.rename(file, d + "/" + newfname)
161+
curproc += 1
162+
if curproc == len(files):
163+
updatefilelist(values["-SHOWPATHS-"], getfiles(d, values['-REC-']))
164+
148165

149166
### GUI Logic
150167

@@ -166,6 +183,10 @@ def filelog(logmsg):
166183
updatefilelist(values["-SHOWPATHS-"], currentfiles)
167184
folderset = True
168185
filelog("Folder Set")
186+
if event == 'Refresh':
187+
if folderset == True:
188+
currentfiles = getfiles(folder, values['-REC-'])
189+
updatefilelist(values["-SHOWPATHS-"], currentfiles)
169190

170191
if event == '-REC-':
171192
if folderset == True:
@@ -174,23 +195,32 @@ def filelog(logmsg):
174195

175196
if event == '-SHOWPATHS-':
176197
if folderset == True:
198+
currentfiles = getfiles(folder, values['-REC-'])
177199
updatefilelist(values["-SHOWPATHS-"], currentfiles)
178200

179201

180202
if event == 'Process':
181203
if folderset == True:
182204
currentfiles = getfiles(folder, values['-REC-'])
183-
try:
184-
if values['-BIT-'] == True:
185-
process_32to24(currentfiles)
205+
try:
186206
if values['-TRIM-'] == True:
187207
trimsilence(currentfiles)
188208
if values['-NORM-'] == True:
189-
normalize(currentfiles)
190-
if values['-EMPTY-'] == True:
191-
rmempty(currentfiles, values['-EMPTYFL-'])
209+
normalize(currentfiles)
210+
if values['-BIT-'] == True:
211+
process_32to24(currentfiles)
192212
if values['-PREFIXBOOL-'] == True:
193213
setprefix(currentfiles, values["-PREFIXSTR-"])
214+
if values['-REPL-'] == True:
215+
try:
216+
findrepl(currentfiles, values["-RPLFROM-"], values["-RPLTO-"])
217+
except FileNotFoundError:
218+
findrepl(getfiles(folder, values['-REC-']), values["-RPLFROM-"], values["-RPLTO-"])
219+
220+
221+
##### Destructive, should be last!
222+
if values['-EMPTY-'] == True:
223+
rmempty(currentfiles, values['-EMPTYFL-'])
194224

195225

196226
except NameError as error:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ These tools include:
1010
- Remove empty wav files (Aswell as _Current & _Master files for FL)
1111
- Convert 32bit to 24bit for compatibility of certain programs
1212
- Add prefixes to your files (KICK_Filename.wav)
13+
- Find and replace text.
1314

1415
To install:
1516
Download a built .exe from [here](https://www.github.com/diontimmer/AudioBatchScripts/releases/latest/download/ABS.exe) and run it.

0 commit comments

Comments
 (0)