-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay_gain
executable file
·37 lines (30 loc) · 949 Bytes
/
replay_gain
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
#!/usr/bin/env python3
import os
import subprocess
import pathlib
gain_bin = {'flac': ['metaflac', '--add-replay-gain'],
'mp3': ['replaygain', '-f'],
'ogg': ['vorbisgain', '-a', '-f'],
}
def call_ignore_exception(command):
try:
print("Running " + " ".join(command))
subprocess.check_call(command)
except subprocess.CalledProcessError:
pass
def get_files_pth_s(pth, ext):
pth = pathlib.PosixPath(pth)
pth_s = list(pth.glob('*.' + ext))
return sorted([str(pt) for pt in pth_s])
def replay_gain(folder_pth):
for ext in gain_bin.keys():
pth_s = get_files_pth_s(folder_pth, ext)
if pth_s:
command = gain_bin[ext] + pth_s
call_ignore_exception(command)
if __name__ == '__main__':
for a, b, _ in os.walk('.'):
for d in b:
folder_pth = a + "/" + d
replay_gain(folder_pth)
print("Done")